# IDistributedApplicationBuilder

- Kind: `interface`
- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Version: `13.3.0`
- Namespace: `Aspire.Hosting`
- Target framework: `net8.0`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/IDistributedApplicationBuilder.cs)

A builder for creating instances of [DistributedApplication](/reference/api/csharp/aspire.hosting/distributedapplication.md).

## Definition

```csharp
namespace Aspire.Hosting;

public interface IDistributedApplicationBuilder
{
    // ...
}
```

## ATS metadata

### ATS export

- Type ID: `Aspire.Hosting/IDistributedApplicationBuilder`
- Public instance properties are exported as ATS capabilities.

## Remarks

The [IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md) is the central interface for defining the resources which are orchestrated by the [DistributedApplication](/reference/api/csharp/aspire.hosting/distributedapplication.md) when the app host is launched.

To create an instance of the [IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md) interface developers should use the [DistributedApplication.CreateBuilder](/reference/api/csharp/aspire.hosting/distributedapplication/methods.md#createbuilder) method. Once the builder is created extension methods which target the [IDistributedApplicationBuilder](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder.md) 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](/reference/api/csharp/aspire.hosting/distributedapplication/methods.md#createbuilder) method.

The [AddRedis](https://learn.microsoft.com/dotnet/api/aspire.hosting.redisbuilderextensions.addredis) and [AddPostgres](https://learn.microsoft.com/dotnet/api/aspire.hosting.postgresbuilderextensions.addpostgres) methods are used to add Redis and PostgreSQL container resources. The results of the methods are stored in variables for later use.

```csharp
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();
```

## Properties

- [AppHostAssembly](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder/properties.md#apphostassembly) : `Assembly?` `abstract` `get` -- Assembly of the app host project.
- [AppHostDirectory](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder/properties.md#apphostdirectory) : `string` `abstract` `get` -- Directory of the project where the app host is located. Defaults to the content root if there's no project.
- [Configuration](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder/properties.md#configuration) : `ConfigurationManager` `abstract` `get` -- Gets the set of key/value configuration properties.
- [Environment](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder/properties.md#environment) : `IHostEnvironment` `abstract` `get` -- Gets the information about the hosting environment an application is running in.
- [Eventing](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder/properties.md#eventing) : [IDistributedApplicationEventing](/reference/api/csharp/aspire.hosting/idistributedapplicationeventing.md) `abstract` `get` -- Eventing infrastructure for AppHost lifecycle.
- [ExecutionContext](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder/properties.md#executioncontext) : [DistributedApplicationExecutionContext](/reference/api/csharp/aspire.hosting/distributedapplicationexecutioncontext.md) `abstract` `get` -- Execution context for this invocation of the AppHost.
- [FileSystemService](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder/properties.md#filesystemservice) : [IFileSystemService](/reference/api/csharp/aspire.hosting/ifilesystemservice.md) `virtual` `get` `experimental` -- Gets the service for managing Aspire file system operations.
- [Pipeline](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder/properties.md#pipeline) : [IDistributedApplicationPipeline](/reference/api/csharp/aspire.hosting/idistributedapplicationpipeline.md) `abstract` `get` `experimental` -- Gets the deployment pipeline for this distributed application.
- [Resources](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder/properties.md#resources) : [IResourceCollection](/reference/api/csharp/aspire.hosting/iresourcecollection.md) `abstract` `get` -- Gets the collection of resources for the distributed application.
- [Services](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder/properties.md#services) : `IServiceCollection` `abstract` `get` `ats ignored` -- Gets a collection of services for the application to compose. This is useful for adding user provided or framework provided services.
- [UserSecretsManager](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder/properties.md#usersecretsmanager) : [IUserSecretsManager](/reference/api/csharp/aspire.hosting/iusersecretsmanager.md) `virtual` `get` `experimental` -- Gets the service for managing user secrets.

## Methods

- [AddResource(T)](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder/methods.md#addresource-t) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `abstract` -- Adds a resource of type `T` to the distributed application.
- [Build](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder/methods.md#build) : [DistributedApplication](/reference/api/csharp/aspire.hosting/distributedapplication.md) `abstract` `ats export` -- Builds and returns a new [DistributedApplication](/reference/api/csharp/aspire.hosting/distributedapplication.md) instance. This can only be called once.
- [CreateResourceBuilder(T)](/reference/api/csharp/aspire.hosting/idistributedapplicationbuilder/methods.md#createresourcebuilder-t) : [IResourceBuilder<T>](/reference/api/csharp/aspire.hosting/iresourcebuilder-1.md) `abstract` -- Creates a new resource builder based on an existing resource.
