IDistributedApplicationBuilder
DistributedApplication. namespace Aspire.Hosting;
public interface IDistributedApplicationBuilder{ // ...}Remarks
Section titled Remarks The IDistributedApplicationBuilder is the central interface for defining the resources which are orchestrated by the DistributedApplication when the app host is launched.
To create an instance of the IDistributedApplicationBuilder interface developers should use the DistributedApplication.CreateBuilder method. Once the builder is created extension methods which target the IDistributedApplicationBuilder interface can be used to add resources to the distributed application.
This example shows a distributed application that contains a .NET project (InventoryService) that uses a Redis cache and a PostgreSQL database. The builder is created using the DistributedApplication.CreateBuilder method.
The AddRedis and AddPostgres methods are used to add Redis and PostgreSQL container resources. The results of the methods are stored in variables for later use.
var builder = DistributedApplication.CreateBuilder(args);var cache = builder.AddRedis("cache");var inventoryDatabase = builder.AddPostgres( "postgres").AddDatabase("inventory");builder.AddProject<Projects.InventoryService>("inventoryservice") .WithReference(cache) .WithReference(inventory);builder.Build().Run();Properties11
Section titled PropertiesAppHostAssemblyabstractgetAssembly?AppHostDirectoryabstractgetstringConfigurationabstractgetConfigurationManagerEnvironmentabstractgetIHostEnvironmentEventingabstractgetExecutionContextabstractgetFileSystemServicevirtualgetexperimentalPipelineabstractgetexperimentalResourcesabstractgetServicesabstractgetIServiceCollectionUserSecretsManagervirtualgetexperimentalMethods3
Section titled MethodsAddResource(T)abstractT to the distributed application. BuildabstractDistributedApplication instance. This can only be called once. CreateResourceBuilder(T)abstract