# BeforeStartEvent Constructors

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

This event is published before the application starts.

## BeforeStartEvent(IServiceProvider, DistributedApplicationModel)

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

This event is published before the application starts.

```csharp
public class BeforeStartEvent
{
    public BeforeStartEvent(
        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.BeforeStartAsync(DistributedApplicationModel, CancellationToken)](/reference/api/csharp/aspire.hosting/idistributedapplicationlifecyclehook/methods.md#beforestartasync-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.BeforeStartAsync(DistributedApplicationModel, CancellationToken)](/reference/api/csharp/aspire.hosting/idistributedapplicationlifecyclehook/methods.md#beforestartasync-distributedapplicationmodel-cancellationtoken).

## Examples

Subscribe to the event and resolve the distributed application model.

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