共用方式為


BeforeStartEvent(IServiceProvider, DistributedApplicationModel) Constructor

Definition

This event is published before the application starts.

public BeforeStartEvent (IServiceProvider services, Aspire.Hosting.ApplicationModel.DistributedApplicationModel model);
new Aspire.Hosting.ApplicationModel.BeforeStartEvent : IServiceProvider * Aspire.Hosting.ApplicationModel.DistributedApplicationModel -> Aspire.Hosting.ApplicationModel.BeforeStartEvent
Public Sub New (services As IServiceProvider, model As DistributedApplicationModel)

Parameters

services
IServiceProvider

The IServiceProvider instance.

Examples

Subscribe to the BeforeStartEvent event and resolve the distributed application model.

var builder = DistributedApplication.CreateBuilder(args);
builder.Eventing.Subscribe<BeforeStartEvent>(async (@event, cancellationToken) => {
  var appModel = @event.ServiceProvider.GetRequiredService<DistributedApplicationModel>();
  // Mutate the distributed application model.
});

Remarks

Subscribing to this event is analogous to implementing the BeforeStartAsync(DistributedApplicationModel, CancellationToken) method. This event provides access to the IServiceProvider interface to resolve dependencies including DistributedApplicationModel service which is passed in as an argument in BeforeStartAsync(DistributedApplicationModel, CancellationToken).

Applies to