Ir al contenido

Get started with the Azure App Configuration integrations

Esta página aún no está disponible en tu idioma.

Azure App Configuration logo

Azure App Configuration provides a service to centrally manage application settings and feature flags. Modern programs, especially programs running in a cloud, generally have many components that are distributed in nature. Spreading configuration settings across these components can lead to hard-to-troubleshoot errors during an application deployment. The Aspire Azure App Configuration integration enables you to connect to existing App Configuration instances or create new instances all from your AppHost.

In this introduction, you’ll see how to install and use the Aspire Azure App Configuration integrations in a simple configuration. If you already have this knowledge, see Azure App Configuration Hosting integration for full reference details.

To begin, install the Aspire Azure App Configuration Hosting integration in your Aspire AppHost project. This integration allows you to create and manage Azure App Configuration resources from your Aspire hosting projects:

Aspire CLI — Añadir paquete Aspire.Hosting.Azure.AppConfiguration
aspire add azure-appconfiguration

La CLI de Aspire es interactiva; asegúrate de seleccionar el resultado adecuado cuando se te pida:

Aspire CLI — Ejemplo de salida
Select an integration to add:
> azure-appconfiguration (Aspire.Hosting.Azure.AppConfiguration)
> Other results listed as selectable options...

Next, in the AppHost project, create an Azure App Configuration resource and pass it to the consuming client projects:

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var appConfig = builder.AddAzureAppConfiguration("config");
builder.AddProject<Projects.WebApplication>("web")
.WithReference(appConfig);
// After adding all resources, run the app...
builder.Build().Run();

To get started with the Aspire Azure App Configuration client integration, 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 the Program.cs file of your client-consuming project, call the AddAzureAppConfiguration extension method to register the required services:

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

You can then retrieve the IConfiguration instance using dependency injection:

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