Watch Aspire live streamsDocsTry Aspire
Watch Aspire live streamsDocsTry

DistributedApplication

Classnet10.0
📦 Aspire.Hosting v13.5.4
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 an 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 Aspire dashboard (see DistributedApplicationOptions.DisableDashboard) or allowing unsecured communication between the browser and dashboard, and dashboard and AppHost (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
View all properties
View all methods