Skip to content
Docs Try Aspire

DistributedApplication

Class net10.0
📦 Aspire.Hosting v13.1.2
Represents a distributed application that implements the Hosting.IHost and IAsyncDisposable interfaces.
namespace Aspire.Hosting;
public class DistributedApplication
: Microsoft.Extensions.Hosting.IHost,
System.IAsyncDisposable,
System.IDisposable
{
// ...
}
IHostIAsyncDisposableIDisposable

The DistributedApplication is an implementation of the Hosting.IHost interface that orchestrates a .NET Aspire application. To build an instance of the DistributedApplication class, use the DistributedApplication.CreateBuilder method to create an instance of the IDistributedApplicationBuilder interface. Using the IDistributedApplicationBuilder interface you can configure the resources that comprise the distributed application and describe the dependencies between them.

Once the distributed application has been defined use the IDistributedApplicationBuilder.Build method to create an instance of the DistributedApplication class. The DistributedApplication class exposes a DistributedApplication.Run method which then starts the distributed application and its resources.

The DistributedApplication.CreateBuilder method provides additional options for constructing the IDistributedApplicationBuilder including disabling the .NET Aspire dashboard (see DistributedApplicationOptions.DisableDashboard) or allowing unsecured communication between the browser and dashboard, and dashboard and app host (see DistributedApplicationOptions.AllowUnsecuredTransport.

The following example shows creating a PostgreSQL server resource with a database and referencing that database in a .NET project.
var builder = DistributedApplication.CreateBuilder(args);
var inventoryDatabase = builder.AddPostgres(
"mypostgres").AddDatabase("inventory");
builder.AddProject<Projects.InventoryService>()
.WithReference(inventoryDatabase);
builder.Build().Run();
View all constructors
ResourceCommandsget
Gets the service for executing resource commands.
ResourceNotificationsget
Gets the service for monitoring and responding to resource state changes in the distributed application.
Servicesget
IServiceProvider
Gets the IServiceProvider instance configured for the application.
View all properties
View all methods