DistributedApplication
Hosting.IHost and IAsyncDisposable interfaces. namespace Aspire.Hosting;
public class DistributedApplication : Microsoft.Extensions.Hosting.IHost, System.IAsyncDisposable, System.IDisposable{ // ...}Remarks
Section titled Remarks 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.
var builder = DistributedApplication.CreateBuilder(args);var inventoryDatabase = builder.AddPostgres( "mypostgres").AddDatabase("inventory");builder.AddProject<Projects.InventoryService>() .WithReference(inventoryDatabase);
builder.Build().Run();Constructors1
Section titled ConstructorsProperties3
Section titled PropertiesResourceCommandsgetResourceNotificationsgetServicesgetIServiceProviderIServiceProvider instance configured for the application. Methods9
Section titled MethodsCreateBuilderstaticIDistributedApplicationBuilder interface. CreateBuilder(string[])staticIDistributedApplicationBuilder with the specified command-line arguments. CreateBuilder(DistributedApplicationOptions)staticIDistributedApplicationBuilder interface with the specified options. DisposevirtualHosting.IHost. DisposeAsyncvirtualValueTaskHosting.IHost. RunHosting.IHostedService instances are stopped. RunAsync(CancellationToken)virtualTaskHosting.IHostedService instances are stopped. StartAsync(CancellationToken)virtualTaskHosting.IHostedService objects configured for the program. The application will run until interrupted or until StopApplication is called. StopAsync(CancellationToken)virtualTask