Skip to content
DocsTry Aspire
DocsTry

BeforeStartEvent Constructors

ClassConstructors1 member
This event is published before the application starts.
Constructor(IServiceProvider, DistributedApplicationModel)Section titled Constructor(IServiceProvider, DistributedApplicationModel)
This event is published before the application starts.
public class BeforeStartEvent
{
public BeforeStartEvent(
IServiceProvider services,
DistributedApplicationModel model)
{
// ...
}
}
servicesIServiceProviderThe IServiceProvider instance.
Subscribing to this event is analogous to implementing the IDistributedApplicationLifecycleHook.BeforeStartAsync method. This event provides access to the IServiceProvider interface to resolve dependencies including DistributedApplicationModel service which is passed in as an argument in IDistributedApplicationLifecycleHook.BeforeStartAsync.

Subscribe to the 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.
});