Skip to content
Docs Try Aspire

AfterEndpointsAllocatedEvent Constructors

Class Constructors 1 member
This event is published after all endpoints have been allocated.
Constructor(IServiceProvider, DistributedApplicationModel) Section titled Constructor(IServiceProvider, DistributedApplicationModel)
This event is published after all endpoints have been allocated.
public class AfterEndpointsAllocatedEvent
{
public AfterEndpointsAllocatedEvent(
IServiceProvider services,
DistributedApplicationModel model)
{
// ...
}
}
services IServiceProvider The IServiceProvider instance.
Subscribing to this event is analogous to implementing the IDistributedApplicationLifecycleHook.AfterEndpointsAllocatedAsync method. This event provides access to the IServiceProvider interface to resolve dependencies including DistributedApplicationModel service which is passed in as an argument in IDistributedApplicationLifecycleHook.AfterEndpointsAllocatedAsync. Subscribe to the AfterEndpointsAllocatedEvent event and resolve the distributed application model.
var builder = DistributedApplication.CreateBuilder(args);
builder.Eventing.Subscribe<AfterEndpointsAllocatedEvent>(
async (@event, cancellationToken) => {
var appModel = @event
.ServiceProvider
.GetRequiredService<DistributedApplicationModel>(
);
// Update configuration of resource based on final endpoint configuration
});