# AfterEndpointsAllocatedEvent Constructors

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [AfterEndpointsAllocatedEvent](/reference/api/csharp/aspire.hosting/afterendpointsallocatedevent.md)
- Kind: `Constructors`
- Members: `1`

This event is published after all endpoints have been allocated.

## AfterEndpointsAllocatedEvent(IServiceProvider, DistributedApplicationModel)

- Name: `Constructor(IServiceProvider, DistributedApplicationModel)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/AfterEndpointsAllocatedEvent.cs#L30-L40)

This event is published after all endpoints have been allocated.

```csharp
public class AfterEndpointsAllocatedEvent
{
    public AfterEndpointsAllocatedEvent(
        IServiceProvider services,
        DistributedApplicationModel model)
    {
        // ...
    }
}
```

## Parameters

- `services` (`IServiceProvider`)
  The `IServiceProvider` instance.
- `model` ([DistributedApplicationModel](/reference/api/csharp/aspire.hosting/distributedapplicationmodel.md))
  The [DistributedApplicationModel](/reference/api/csharp/aspire.hosting/distributedapplicationmodel.md) instance.

## Remarks

Subscribing to this event is analogous to implementing the [IDistributedApplicationLifecycleHook.AfterEndpointsAllocatedAsync(DistributedApplicationModel, CancellationToken)](/reference/api/csharp/aspire.hosting/idistributedapplicationlifecyclehook/methods.md#afterendpointsallocatedasync-distributedapplicationmodel-cancellationtoken) method. This event provides access to the `IServiceProvider` interface to resolve dependencies including [DistributedApplicationModel](/reference/api/csharp/aspire.hosting/distributedapplicationmodel.md) service which is passed in as an argument in [IDistributedApplicationLifecycleHook.AfterEndpointsAllocatedAsync(DistributedApplicationModel, CancellationToken)](/reference/api/csharp/aspire.hosting/idistributedapplicationlifecyclehook/methods.md#afterendpointsallocatedasync-distributedapplicationmodel-cancellationtoken). Subscribe to the [AfterEndpointsAllocatedEvent](/reference/api/csharp/aspire.hosting/afterendpointsallocatedevent.md) event and resolve the distributed application model.

```csharp
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
});
```
