# DistributedApplication Properties

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [DistributedApplication](/reference/api/csharp/aspire.hosting/distributedapplication.md)
- Kind: `Properties`
- Members: `3`

Represents a distributed application that implements the `Hosting.IHost` and `IAsyncDisposable` interfaces.

## ResourceCommands

- Name: `ResourceCommands`
- Modifiers: `get`
- Returns: [ResourceCommandService](/reference/api/csharp/aspire.hosting/resourcecommandservice.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/DistributedApplication.cs#L372)

Gets the service for executing resource commands.

```csharp
public ResourceCommandService ResourceCommands { get; }
```

## Remarks

Two common use cases for the [ResourceCommandService](/reference/api/csharp/aspire.hosting/resourcecommandservice.md) are:

- Progamatically executing resource commands in a running app host.
- Unit or integration testing resource commands.

## ResourceNotifications

- Name: `ResourceNotifications`
- Modifiers: `get`
- Returns: [ResourceNotificationService](/reference/api/csharp/aspire.hosting/resourcenotificationservice.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/DistributedApplication.cs#L360)

Gets the service for monitoring and responding to resource state changes in the distributed application.

```csharp
public ResourceNotificationService ResourceNotifications { get; }
```

## Remarks

Two common use cases for the [ResourceNotificationService](/reference/api/csharp/aspire.hosting/resourcenotificationservice.md) are:

- Database seeding.
- Integration test readiness checks.

Wait for resource readiness:

```csharp
await app.ResourceNotifications.WaitForResourceHealthyAsync("postgres");
```

Monitor state changes:

```csharp
await foreach (var update in app.ResourceNotifications.WatchAsync(cancellationToken))
{
    Console.WriteLine($"Resource {update.Resource.Name} state: {update.Snapshot.State?.Text}");
}
```

Wait for a specific state:

```csharp
await app.ResourceNotifications.WaitForResourceAsync("worker", KnownResourceStates.Running);
```

Seed a database once it becomes available:

```csharp
// Wait for the database to be healthy before seeding
await app.ResourceNotifications.WaitForResourceHealthyAsync("postgres");
using var scope = app.Services.CreateScope();
var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
await dbContext.Database.EnsureCreatedAsync();
if (!dbContext.Products.Any())
{
    await dbContext.Products.AddRangeAsync(
    [
        new Product { Name = "Product 1", Price = 10.99m },
        new Product { Name = "Product 2", Price = 20.99m }
    ]);
    await dbContext.SaveChangesAsync();
}
```

## Services

- Name: `Services`
- Modifiers: `get`
- Returns: `IServiceProvider`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/DistributedApplication.cs#L308)

Gets the `IServiceProvider` instance configured for the application.

```csharp
public IServiceProvider Services { get; }
```

## Remarks

The [DistributedApplication](/reference/api/csharp/aspire.hosting/distributedapplication.md) is an `Hosting.IHost` implementation and as such exposes a [DistributedApplication.Services](/reference/api/csharp/aspire.hosting/distributedapplication/properties.md#services) property which allows developers to get services from the dependency injection container after [DistributedApplication](/reference/api/csharp/aspire.hosting/distributedapplication.md) instance has been built using the [IDistributedApplicationBuilder.Build](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder/methods.md#build) method.

To add services to the dependency injection container developers should use the [IDistributedApplicationBuilder.Services](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder/properties.md#services) property to access the `DependencyInjection.IServiceCollection` instance.
