IDistributedApplicationBuilder.ExecutionContext Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Execution context for this invocation of the AppHost.
public Aspire.Hosting.DistributedApplicationExecutionContext ExecutionContext { get; }
member this.ExecutionContext : Aspire.Hosting.DistributedApplicationExecutionContext
Public ReadOnly Property ExecutionContext As DistributedApplicationExecutionContext
Property Value
Examples
An example of using the IsRunMode property on the IDistributedApplicationBuilder via the ApplicationBuilder. 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;
}
Remarks
The ExecutionContext property provides access key information about the context in which the distributed application is running. The most important properties that the DistributedApplicationExecutionContext provides is the IsPublishMode and IsRunMode properties. Developers building .NET 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.
Applies to
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈