Skip to content
Docs Try Aspire

IDistributedApplicationBuilder

Interface net10.0
📦 Aspire.Hosting v13.1.2
A builder for creating instances of DistributedApplication.
namespace Aspire.Hosting;
public interface IDistributedApplicationBuilder
{
// ...
}

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();
View all properties
AddResource(T)abstract
Adds a resource of type T to the distributed application.
Buildabstract
Builds and returns a new DistributedApplication instance. This can only be called once.
CreateResourceBuilder(T)abstract
Creates a new resource builder based on an existing resource.
View all methods