Share via


IDistributedApplicationBuilder Interface

Definition

A builder for creating instances of DistributedApplication.

public interface IDistributedApplicationBuilder
type IDistributedApplicationBuilder = interface
Public Interface IDistributedApplicationBuilder
Derived

Examples

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 CreateBuilder(String[]) 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();

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 CreateBuilder(String[]) method. Once the builder is created extension methods which target the IDistributedApplicationBuilder interface can be used to add resources to the distributed application.

Properties

AppHostDirectory

Directory of the project where the app host is located. Defaults to the content root if there's no project.

Configuration

Gets the set of key-value configuration properties.

Environment

Gets information about the hosting environment an application is running in.

ExecutionContext

Execution context for this invocation of the AppHost.

Resources

Gets the collection of resources for the distributed application.

Services

Gets a collection of services for the application to compose. This property is useful for adding user-provided or framework-provided services.

Methods

AddResource<T>(T)

Adds a resource of type T to the distributed application.

Build()

Builds and returns a new DistributedApplication instance. This can only be called once.

CreateResourceBuilder<T>(T)

Creates a new resource builder based on an existing resource.

Extension Methods

AddAzureAppConfiguration(IDistributedApplicationBuilder, String)

Adds an Azure App Configuration resource to the application model.

AddAzureAppConfiguration(IDistributedApplicationBuilder, String, Action<IResourceBuilder<AzureAppConfigurationResource>,ResourceModuleConstruct, AppConfigurationStore>)

Adds an Azure App Configuration resource to the application model.

AddAzureApplicationInsights(IDistributedApplicationBuilder, String)

Adds an Azure Application Insights resource to the application model.

AddAzureApplicationInsights(IDistributedApplicationBuilder, String, IResourceBuilder<AzureLogAnalyticsWorkspaceResource>)

Adds an Azure Application Insights resource to the application model.

AddAzureApplicationInsights(IDistributedApplicationBuilder, String, IResourceBuilder<AzureLogAnalyticsWorkspaceResource>, Action<IResourceBuilder<AzureApplicationInsightsResource>, ResourceModuleConstruct,ApplicationInsightsComponent>)

Adds an Azure Application Insights resource to the application model.

AddAzureApplicationInsights(IDistributedApplicationBuilder, String, Action<IResourceBuilder<AzureApplicationInsightsResource>,ResourceModuleConstruct, ApplicationInsightsComponent>)

Adds an Azure Application Insights resource to the application model.

AddBicepTemplate(IDistributedApplicationBuilder, String, String)

Adds an Azure Bicep resource to the application model.

AddBicepTemplateString(IDistributedApplicationBuilder, String, String)

Adds an Azure Bicep resource to the application model.

AddAzureConstruct(IDistributedApplicationBuilder, String, Action<ResourceModuleConstruct>)

Adds an Azure construct resource to the application model.

AddAzureCosmosDB(IDistributedApplicationBuilder, String)

Adds an Azure Cosmos DB connection to the application model.

AddAzureCosmosDB(IDistributedApplicationBuilder, String, Action<IResourceBuilder<AzureCosmosDBResource>, ResourceModuleConstruct,CosmosDBAccount,IEnumerable<CosmosDBSqlDatabase>>)

Adds an Azure Cosmos DB connection to the application model.

AddAzureEventHubs(IDistributedApplicationBuilder, String)

Adds an Azure Event Hubs Namespace resource to the application model. This resource can be used to create Event Hub resources.

AddAzureEventHubs(IDistributedApplicationBuilder, String, Action<IResourceBuilder<AzureEventHubsResource>, ResourceModuleConstruct,EventHubsNamespace>)

Adds an Azure Event Hubs Namespace resource to the application model. This resource can be used to create Event Hub resources.

AddAzureKeyVault(IDistributedApplicationBuilder, String)

Adds an Azure Key Vault resource to the application model.

AddAzureKeyVault(IDistributedApplicationBuilder, String, Action<IResourceBuilder<AzureKeyVaultResource>,ResourceModuleConstruct,KeyVault>)

Adds an Azure Key Vault resource to the application model.

AddAzureLogAnalyticsWorkspace(IDistributedApplicationBuilder, String)

Adds an Azure Application Insights resource to the application model.

AddAzureLogAnalyticsWorkspace(IDistributedApplicationBuilder, String, Action<IResourceBuilder<AzureLogAnalyticsWorkspaceResource>, ResourceModuleConstruct,OperationalInsightsWorkspace>)

Adds an Azure Log Analytics Workspace resource to the application model.

AddAzureOpenAI(IDistributedApplicationBuilder, String)

Adds an Azure OpenAI resource to the application model.

AddAzureOpenAI(IDistributedApplicationBuilder, String, Action<IResourceBuilder<AzureOpenAIResource>, ResourceModuleConstruct,CognitiveServicesAccount,IEnumerable<CognitiveServicesAccountDeployment>>)

Adds an Azure OpenAI resource to the application model.

AddAzureProvisioning(IDistributedApplicationBuilder)

Adds support for generating azure resources dynamically during application startup. The application must configure the appropriate subscription, location.

AddAzureSearch(IDistributedApplicationBuilder, String)

Adds an Azure AI Search service resource to the application model.

AddAzureSearch(IDistributedApplicationBuilder, String, Action<IResourceBuilder<AzureSearchResource>,ResourceModuleConstruct,SearchService>)

Adds an Azure AI Search service resource to the application model.

AddAzureServiceBus(IDistributedApplicationBuilder, String)

Adds an Azure Service Bus Namespace resource to the application model. This resource can be used to create queue, topic, and subscription resources.

AddAzureServiceBus(IDistributedApplicationBuilder, String, Action<IResourceBuilder<AzureServiceBusResource>, ResourceModuleConstruct,ServiceBusNamespace>)

Adds an Azure Service Bus Namespace resource to the application model. This resource can be used to create queue, topic, and subscription resources.

AddAzureSignalR(IDistributedApplicationBuilder, String)

Adds an Azure SignalR resource to the application model.

AddAzureSignalR(IDistributedApplicationBuilder, String, Action<IResourceBuilder<AzureSignalRResource>,ResourceModuleConstruct,SignalRService>)

Adds an Azure SignalR resource to the application model.

AddAzureStorage(IDistributedApplicationBuilder, String)

Adds an Azure Storage resource to the application model.This resource can be used to create Azure blob, table, and queue resources.

AddAzureStorage(IDistributedApplicationBuilder, String, Action<IResourceBuilder<AzureStorageResource>,ResourceModuleConstruct,StorageAccount>)

Adds an Azure Storage resource to the application model.This resource can be used to create Azure blob, table, and queue resources.

AddAWSCloudFormationStack(IDistributedApplicationBuilder, String)

Add a CloudFormation stack for provisioning application resources.

AddAWSCloudFormationTemplate(IDistributedApplicationBuilder, String, String)

Add a CloudFormation stack for provisioning application resources.

AddContainer(IDistributedApplicationBuilder, String, String)

Adds a container resource to the application. Uses the "latest" tag.

AddContainer(IDistributedApplicationBuilder, String, String, String)

Adds a container resource to the application.

AddExecutable(IDistributedApplicationBuilder, String, String, String, String[])

Adds an executable resource to the application model.

AddDapr(IDistributedApplicationBuilder, Action<DaprOptions>)

Adds Dapr support to Aspire, including the ability to add Dapr sidecar to application resource.

AddDaprComponent(IDistributedApplicationBuilder, String, String, DaprComponentOptions)

Adds a Dapr component to the application model.

AddDaprPubSub(IDistributedApplicationBuilder, String, DaprComponentOptions)

Adds a "generic" Dapr pub-sub component to the application model. Aspire will configure an appropriate type when running or deploying.

AddDaprStateStore(IDistributedApplicationBuilder, String, DaprComponentOptions)

Adds a Dapr state store component to the application model. Aspire will configure an appropriate type when running or deploying.

AddKafka(IDistributedApplicationBuilder, String, Nullable<Int32>)

Adds a Kafka resource to the application. A container is used for local development. This version the package defaults to the 7.6.1 tag of the confluentinc/confluent-local container image.

AddMongoDB(IDistributedApplicationBuilder, String, Nullable<Int32>)

Adds a MongoDB resource to the application model. A container is used for local development. This version the package defaults to the 7.0.8 tag of the mongo container image.

AddMySql(IDistributedApplicationBuilder, String, IResourceBuilder<ParameterResource>, Nullable<Int32>)

Adds a MySQL server resource to the application model. For local development a container is used. This version the package defaults to the 8.3.0 tag of the mysql container image

AddNats(IDistributedApplicationBuilder, String, Nullable<Int32>)

Adds a NATS server resource to the application model. A container is used for local development.

AddNodeApp(IDistributedApplicationBuilder, String, String, String, String[])

Adds a node application to the application model. Node should available on the PATH.

AddNpmApp(IDistributedApplicationBuilder, String, String, String, String[])

Adds a node application to the application model. Executes the npm command with the specified script name.

AddOracle(IDistributedApplicationBuilder, String, IResourceBuilder<ParameterResource>, Nullable<Int32>)

Adds a Oracle Server resource to the application model. A container is used for local development. This version the package defaults to the 23.3.0.0 tag of the container-registry.oracle.com/database/free container image

AddOrleans(IDistributedApplicationBuilder, String)

Adds an Orleans service to the application.

AddConnectionString(IDistributedApplicationBuilder, String, String)

Adds a parameter to the distributed application but wrapped in a resource with a connection string for use with WithReference<TDestination>(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithConnectionString>, String, Boolean)

AddParameter(IDistributedApplicationBuilder, String, Boolean)

Adds a parameter resource to the application.

AddPostgres(IDistributedApplicationBuilder, String, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>, Nullable<Int32>)

Adds a PostgreSQL resource to the application model. A container is used for local development. This version the package defaults to the 16.2 tag of the postgres container image

AddProject(IDistributedApplicationBuilder, String, String)

Adds a .NET project to the application model.

AddProject(IDistributedApplicationBuilder, String, String, String)

Adds a .NET project to the application model.

AddProject<TProject>(IDistributedApplicationBuilder, String)

Adds a .NET project to the application model.

AddProject<TProject>(IDistributedApplicationBuilder, String, String)

Adds a .NET project to the application model. By default, this will exist in a Projects namespace. e.g. Projects.MyProject. If the project is not in a Projects namespace, make sure a project reference is added from the AppHost project to the target project.

AddQdrant(IDistributedApplicationBuilder, String, IResourceBuilder<ParameterResource>, Nullable<Int32>, Nullable<Int32>)

Adds a Qdrant resource to the application. A container is used for local development.

AddRabbitMQ(IDistributedApplicationBuilder, String, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>, Nullable<Int32>)

Adds a RabbitMQ container to the application model.

AddRedis(IDistributedApplicationBuilder, String, Nullable<Int32>)

Adds a Redis container to the application model.

AddAWSSDKConfig(IDistributedApplicationBuilder)

Add a configuration for resolving region and credentials for the AWS SDK for .NET.

AddSeq(IDistributedApplicationBuilder, String, Nullable<Int32>)

Adds a Seq server resource to the application model. A container is used for local development.

AddSqlServer(IDistributedApplicationBuilder, String, IResourceBuilder<ParameterResource>, Nullable<Int32>)

Adds a SQL Server resource to the application model. A container is used for local development.

Applies to