Перейти до вмісту
Docs Try Aspire
Docs Try

Connect to Azure App Configuration

Цей контент ще не доступний вашою мовою.

Azure App Configuration logo

This page describes how consuming apps connect to an Azure App Configuration resource that’s already modeled in your AppHost. For the AppHost API surface — adding a store resource, provisioning, emulator, role assignments, and infrastructure customization — see Azure App Configuration Hosting integration.

When you reference an Azure App Configuration resource from your AppHost, Aspire injects the store endpoint into the consuming app as an environment variable. Your app can either read that environment variable directly — the pattern works the same from any language — or, in C#, use the Aspire Azure App Configuration client integration for automatic configuration provider registration and feature flag support.

Aspire exposes each property as an environment variable named [RESOURCE]_[PROPERTY]. For instance, the Endpoint property of a resource called config becomes CONFIG_ENDPOINT.

The Azure App Configuration resource exposes the following connection property:

Property NameDescription
EndpointThe Azure App Configuration store endpoint URL, typically https://<store-name>.azconfig.io

Example connection value:

Endpoint: https://config-abc123.azconfig.io

Pick the language your consuming app is written in. Each example assumes your AppHost adds an Azure App Configuration resource named config and references it from the consuming app.

For C# apps, the recommended approach is the Aspire Azure App Configuration client integration. It registers an Azure App Configuration provider into the IConfiguration pipeline through dependency injection and supports feature flags. If you’d rather read the environment variable directly, see the Read environment variables section at the end of this tab.

Install the 📦 Aspire.Microsoft.Extensions.Configuration.AzureAppConfiguration NuGet package in the client-consuming project:

.NET CLI — Add Aspire.Microsoft.Extensions.Configuration.AzureAppConfiguration package
dotnet add package Aspire.Microsoft.Extensions.Configuration.AzureAppConfiguration

In Program.cs, call AddAzureAppConfiguration on your IHostApplicationBuilder to register the Azure App Configuration provider and populate IConfiguration:

C# — Program.cs
builder.AddAzureAppConfiguration(connectionName: "config");

Resolve the IConfiguration instance through dependency injection:

C# — ExampleService.cs
public class ExampleService(IConfiguration configuration)
{
private readonly string _someValue = configuration["SomeKey"];
}

The AddAzureAppConfiguration method accepts an optional Action<AzureAppConfigurationOptions> delegate. This follows the same pattern as the standard Microsoft.Extensions.Configuration.AzureAppConfiguration package, but Aspire automatically handles the connection — you don’t need to call options.Connect:

C# — Program.cs
builder.AddAzureAppConfiguration(
"config",
configureOptions: options =>
{
// Select specific keys or labels
options.Select("MyApp:*");
options.Select("MyApp:*", "Production");
// Configure refresh
options.ConfigureRefresh(refresh =>
{
refresh.Register("MyApp:Sentinel", refreshAll: true)
.SetRefreshInterval(TimeSpan.FromSeconds(30));
});
});

For more information on available options, see the Azure App Configuration provider reference.

To use feature flags, install the 📦 Microsoft.FeatureManagement NuGet package:

.NET CLI — Add Microsoft.FeatureManagement package
dotnet add package Microsoft.FeatureManagement

Call UseFeatureFlags() through the configureOptions delegate and register feature management services:

C# — Program.cs
builder.AddAzureAppConfiguration(
"config",
configureOptions: options => options.UseFeatureFlags());
builder.Services.AddFeatureManagement();

Evaluate feature flags in your app using IFeatureManager:

C# — Program.cs
app.MapGet("/", async (IFeatureManager featureManager) =>
{
if (await featureManager.IsEnabledAsync("NewFeature"))
{
return Results.Ok("New feature is enabled!");
}
return Results.Ok("Using standard implementation.");
});

For more information, see .NET Feature Management.

The Aspire Azure App Configuration client integration offers multiple ways to provide configuration.

Connection strings. When using a connection string from the ConnectionStrings configuration section, pass the connection name to AddAzureAppConfiguration. The endpoint is retrieved from the ConnectionStrings section:

JSON — appsettings.json
{
"ConnectionStrings": {
"config": "https://{store_name}.azconfig.io"
}
}

Configuration providers. The client integration supports Microsoft.Extensions.Configuration. It loads AzureAppConfigurationSettings from appsettings.json using the Aspire:Microsoft:Extensions:Configuration:AzureAppConfiguration key:

JSON — appsettings.json
{
"Aspire": {
"Microsoft": {
"Extensions": {
"Configuration": {
"AzureAppConfiguration": {
"Endpoint": "YOUR_APPCONFIGURATION_ENDPOINT_URI"
}
}
}
}
}
}

For the complete JSON schema, see ConfigurationSchema.json.

Inline delegates. Pass an Action<AzureAppConfigurationSettings> to configure settings inline:

C# — Program.cs
builder.AddAzureAppConfiguration(
"config",
configureSettings: settings => settings.Endpoint = new Uri("https://YOUR_URI"));

The Azure App Configuration client integration doesn’t register a dedicated health check. App health is monitored through the standard ASP.NET Core health check endpoints.

Logging categories:

  • Microsoft.Extensions.Configuration.AzureAppConfiguration.Refresh

Tracing: The Azure App Configuration client integration doesn’t emit activity sources.

Metrics: The Azure App Configuration client integration doesn’t currently support metrics.

If you prefer not to use the Aspire client integration, you can read the Aspire-injected endpoint from the environment and create a ConfigurationClient directly using the 📦 Azure.Data.AppConfiguration NuGet package:

C# — Program.cs
using Azure.Data.AppConfiguration;
using Azure.Identity;
var endpoint = new Uri(Environment.GetEnvironmentVariable("CONFIG_ENDPOINT")!);
var client = new ConfigurationClient(endpoint, new DefaultAzureCredential());
// Use client to read configuration...