# AfterEndpointsAllocatedEvent

- Kind: `class`
- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Version: `13.3.0`
- Namespace: `Aspire.Hosting.ApplicationModel`
- Target framework: `net8.0`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/AfterEndpointsAllocatedEvent.cs)
- Implements: [IDistributedApplicationEvent](/reference/api/csharp/aspire.hosting/idistributedapplicationevent.md)

This event is published after all endpoints have been allocated.

## Definition

```csharp
namespace Aspire.Hosting.ApplicationModel;

public class AfterEndpointsAllocatedEvent
    : Aspire.Hosting.Eventing.IDistributedApplicationEvent
{
    // ...
}
```

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

## Constructors

- [AfterEndpointsAllocatedEvent(IServiceProvider, DistributedApplicationModel)](/reference/api/csharp/aspire.hosting/afterendpointsallocatedevent/constructors.md#constructor-iserviceprovider-distributedapplicationmodel) -- This event is published after all endpoints have been allocated.

## Properties

- [Model](/reference/api/csharp/aspire.hosting/afterendpointsallocatedevent/properties.md#model) : [DistributedApplicationModel](/reference/api/csharp/aspire.hosting/distributedapplicationmodel.md) `get` -- The [DistributedApplicationModel](/reference/api/csharp/aspire.hosting/distributedapplicationmodel.md) instance.
- [Services](/reference/api/csharp/aspire.hosting/afterendpointsallocatedevent/properties.md#services) : `IServiceProvider` `get` -- The `IServiceProvider` instance.
