IDistributedApplicationBuilder Properties
DistributedApplication . public abstract Assembly? AppHostAssembly { get; }public abstract string AppHostDirectory { get; }public abstract ConfigurationManager Configuration { get; }Remarks
public abstract IHostEnvironment Environment { get; }public abstract IDistributedApplicationEventing Eventing { get; }public abstract DistributedApplicationExecutionContext ExecutionContext { get; }Remarks
The I property provides access key information about the context in which the distributed application is running. The most important properties that the Distributed provides is the Distributed and Distributed properties. Developers building Aspire based applications may whish to change the application model depending on whether they are running locally, or whether they are publishing to the cloud.
An example of using the Distributed property on the I via the I. In this case an extension method is used to generate a stable node name for RabbitMQ for local development runs.
private static IResourceBuilder<RabbitMQServerResource> RunWithStableNodeName( this IResourceBuilder<RabbitMQServerResource> builder){ if (builder.ApplicationBuilder.ExecutionContext.IsRunMode) { builder.WithEnvironment(context => { // Set a stable node name so queue storage is consistent between sessions var nodeName = $"{builder.Resource.Name}@localhost"; context.EnvironmentVariables["RABBITMQ_NODENAME"] = nodeName; }); }
return builder;}public virtual IFileSystemService FileSystemService { get; }Remarks
The I provides a centralized way to manage temporary files and directories used by Aspire, enabling testability and consistent temp file management.
Resources and infrastructure code should use this service instead of static methods like Path. or Directory. to ensure consistent directory management across the application.
public abstract IDistributedApplicationPipeline Pipeline { get; }Remarks
public abstract IResourceCollection Resources { get; }Remarks
public abstract IServiceCollection Services { get; }public virtual IUserSecretsManager UserSecretsManager { get; }Remarks
The I provides a centralized way to manage user secrets used by Aspire, enabling testability and consistent secret management.