Skip to content

Azure App Configuration client integration #8945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Aspire.sln
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Azure.Npgsql.EntityF
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Components.Common.Tests", "tests\Aspire.Components.Common.Tests\Aspire.Components.Common.Tests.csproj", "{30950CEB-2232-F9FC-04FF-ADDCB8AC30A7}"
EndProject
<<<<<<< HEAD
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Azure.AppConfiguration", "src\Components\Aspire.Azure.AppConfiguration\Aspire.Azure.AppConfiguration.csproj", "{C33CE874-27B7-4194-A2E7-D0CD950997CC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Azure.AppConfiguration.Tests", "tests\Aspire.Azure.AppConfiguration.Tests\Aspire.Azure.AppConfiguration.Tests.csproj", "{FE972BF3-F448-4CF0-8544-0056B26BF006}"
=======
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{827E0CD3-B72D-47B6-A68D-7590B98EB39B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Hosting.Azure.ContainerRegistry", "src\Aspire.Hosting.Azure.ContainerRegistry\Aspire.Hosting.Azure.ContainerRegistry.csproj", "{6CBA29C8-FF78-4ABC-BEFA-2A53CB4DB2A3}"
Expand All @@ -672,6 +677,7 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureAppService.ApiService", "playground\AzureAppService\AzureAppService.ApiService\AzureAppService.ApiService.csproj", "{A617DC84-65DA-41B5-B378-6C2F569CEE48}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureAppService.AppHost", "playground\AzureAppService\AzureAppService.AppHost\AzureAppService.AppHost.csproj", "{2C879943-DF34-44FA-B2C3-29D97F24DD76}"
>>>>>>> aad850bcfea054da216d79cdf54b049740daab95
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -3887,6 +3893,32 @@ Global
{30950CEB-2232-F9FC-04FF-ADDCB8AC30A7}.Release|x64.Build.0 = Release|Any CPU
{30950CEB-2232-F9FC-04FF-ADDCB8AC30A7}.Release|x86.ActiveCfg = Release|Any CPU
{30950CEB-2232-F9FC-04FF-ADDCB8AC30A7}.Release|x86.Build.0 = Release|Any CPU
<<<<<<< HEAD
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Debug|x64.ActiveCfg = Debug|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Debug|x64.Build.0 = Debug|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Debug|x86.ActiveCfg = Debug|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Debug|x86.Build.0 = Debug|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Release|Any CPU.Build.0 = Release|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Release|x64.ActiveCfg = Release|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Release|x64.Build.0 = Release|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Release|x86.ActiveCfg = Release|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Release|x86.Build.0 = Release|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Debug|x64.ActiveCfg = Debug|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Debug|x64.Build.0 = Debug|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Debug|x86.ActiveCfg = Debug|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Debug|x86.Build.0 = Debug|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Release|Any CPU.Build.0 = Release|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Release|x64.ActiveCfg = Release|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Release|x64.Build.0 = Release|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Release|x86.ActiveCfg = Release|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Release|x86.Build.0 = Release|Any CPU
=======
{6CBA29C8-FF78-4ABC-BEFA-2A53CB4DB2A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CBA29C8-FF78-4ABC-BEFA-2A53CB4DB2A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CBA29C8-FF78-4ABC-BEFA-2A53CB4DB2A3}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -3935,6 +3967,7 @@ Global
{2C879943-DF34-44FA-B2C3-29D97F24DD76}.Release|x64.Build.0 = Release|Any CPU
{2C879943-DF34-44FA-B2C3-29D97F24DD76}.Release|x86.ActiveCfg = Release|Any CPU
{2C879943-DF34-44FA-B2C3-29D97F24DD76}.Release|x86.Build.0 = Release|Any CPU
>>>>>>> aad850bcfea054da216d79cdf54b049740daab95
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -4252,6 +4285,8 @@ Global
{192747A2-9338-DECF-5C8C-28EB8E13829B} = {27381127-6C45-4B4C-8F18-41FF48DFE4B2}
{8FCA0CFA-7823-6A2F-342A-107A994915B0} = {C424395C-1235-41A4-BF55-07880A04368C}
{30950CEB-2232-F9FC-04FF-ADDCB8AC30A7} = {C424395C-1235-41A4-BF55-07880A04368C}
{C33CE874-27B7-4194-A2E7-D0CD950997CC} = {27381127-6C45-4B4C-8F18-41FF48DFE4B2}
{FE972BF3-F448-4CF0-8544-0056B26BF006} = {C424395C-1235-41A4-BF55-07880A04368C}
{6CBA29C8-FF78-4ABC-BEFA-2A53CB4DB2A3} = {77CFE74A-32EE-400C-8930-5025E8555256}
{5DDF8E89-FBBD-4A6F-BF32-7D2140724941} = {77CFE74A-32EE-400C-8930-5025E8555256}
{2D9974C2-3AB2-FBFD-5156-080508BB7449} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<PackageVersion Include="Azure.Security.KeyVault.Secrets" Version="4.7.0" />
<PackageVersion Include="Azure.Storage.Blobs" Version="12.24.0" />
<PackageVersion Include="Azure.Storage.Queues" Version="12.22.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="8.1.1" />
Copy link
Contributor Author

@zhiyuanliang-ms zhiyuanliang-ms Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for 8.2.0 to have tracing support. (Hopefully, it will be released next week)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the current preview version have the tracing feature? If so then you could complete the PR and just switch the version when it's no more preview.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the current preview version doesn't support tracing.

<PackageVersion Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="8.1.1" />
<PackageVersion Include="Microsoft.Azure.Cosmos" Version="3.47.2" />
<PackageVersion Include="Microsoft.Azure.SignalR" Version="1.30.2" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(DefaultTargetFramework)</TargetFramework>
<IsPackable>true</IsPackable>
<PackageTags>$(ComponentAzurePackageTags) configuration appconfiguration</PackageTags>
<Description>A client for Azure App Configuration that integrates with Aspire.</Description>
<PackageIconFullPath>$(SharedDir)AzureAppConfig_256x.png</PackageIconFullPath>
<NoWarn>$(NoWarn);SYSLIB1100;SYSLIB1101</NoWarn>
<!-- Disable package validation as this package hasn't shipped stable yet. -->
<EnablePackageValidation>false</EnablePackageValidation>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\Common\AzureComponent.cs" Link="AzureComponent.cs" />
<Compile Include="..\Common\ConfigurationSchemaAttributes.cs" Link="ConfigurationSchemaAttributes.cs" />
<Compile Include="..\Common\HealthChecksExtensions.cs" Link="HealthChecksExtensions.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Azure" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Azure.AppConfiguration;
using Azure.Identity;
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Aspire.Azure.Common;

namespace Microsoft.Extensions.Hosting;

/// <summary>
/// Provides extension methods for registering and configuring Azure App Configuration in a .NET Aspire application.
/// </summary>
public static class AspireAppConfigurationExtensions
{
internal const string DefaultConfigSectionName = "Aspire:Azure:AppConfiguration";

/// <summary>
/// Adds the Azure App Configuration to be configuration in the <paramref name="builder"/>.
/// </summary>
/// <param name="builder">The <see cref="IHostApplicationBuilder" /> to read config from and add services to.</param>
/// <param name="connectionName">A name used to retrieve the connection string from the ConnectionStrings configuration section.</param>
/// <param name="configureSettings">An optional method that can be used for customizing the <see cref="AzureAppConfigurationSettings"/>. It's invoked after the settings are read from the configuration.</param>
/// <param name="configureOptions">An optional method that can be used for customizing the <see cref="AzureAppConfigurationOptions"/>.</param>
/// <param name="optional">Determines the behavior of the App Configuration provider when an exception occurs while loading data from server. If false, the exception is thrown. If true, the exception is suppressed and no settings are populated from Azure App Configuration.</param>
/// <remarks>Reads the configuration from "Aspire:Azure:AppConfiguration" section.</remarks>
/// <exception cref="InvalidOperationException">Thrown when mandatory <see cref="AzureAppConfigurationSettings.Endpoint"/> is not provided.</exception>
public static void AddAzureAppConfiguration(
this IHostApplicationBuilder builder,
string connectionName,
Action<AzureAppConfigurationSettings>? configureSettings = null,
Action<AzureAppConfigurationOptions>? configureOptions = null,
bool optional = false)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrEmpty(connectionName);

IConfigurationSection configSection = builder.Configuration.GetSection(DefaultConfigSectionName);

var settings = new AzureAppConfigurationSettings();
configSection.Bind(settings);

if (builder.Configuration.GetConnectionString(connectionName) is string connectionString)
{
((IConnectionStringSettings)settings).ParseConnectionString(connectionString);
}

configureSettings?.Invoke(settings);

if (settings.Endpoint is null)
{
throw new InvalidOperationException($"Endpoint is missing. It should be provided in 'ConnectionStrings:{connectionName}' or under the 'Endpoint' key in the '{DefaultConfigSectionName}' configuration section.");
}

builder.Configuration.AddAzureAppConfiguration(
options =>
{
options.Connect(settings.Endpoint, settings.Credential ?? new DefaultAzureCredential());
configureOptions?.Invoke(options);
},
optional);

builder.Services.AddAzureAppConfiguration(); // register IConfigurationRefresherProvider service

if (!settings.DisableTracing)
{
// WIP: https://github.com/Azure/AppConfiguration-DotnetProvider/pull/645
// Will be supported in the next 8.2.0 release
builder.Services.AddOpenTelemetry()
.WithTracing(traceBuilder =>
traceBuilder.AddSource(["Microsoft.Extensions.Configuration.AzureAppConfiguration"]));
}
}
}
10 changes: 10 additions & 0 deletions src/Components/Aspire.Azure.AppConfiguration/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire;
using Aspire.Azure.AppConfiguration;

[assembly: ConfigurationSchema("Aspire:Azure:AppConfiguration", typeof(AzureAppConfigurationSettings))]

[assembly: LoggingCategories(
"Microsoft.Extensions.Configuration.AzureAppConfiguration.Refresh")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Azure.Common;
using Azure.Core;

namespace Aspire.Azure.AppConfiguration;

/// <summary>
/// Provides the client configuration settings for connecting to Azure App Configuration.
/// </summary>
public sealed class AzureAppConfigurationSettings : IConnectionStringSettings
{
/// <summary>
/// A <see cref="Uri"/> to the App Config store on which the client operates. Appears as "Endpoint" in the Azure portal.
/// This is likely to be similar to "https://{store_name}.azconfig.io".
/// </summary>
public Uri? Endpoint { get; set; }

/// <summary>
/// Gets or sets the credential used to authenticate to the Azure App Configuration.
/// </summary>
public TokenCredential? Credential { get; set; }

/// <summary>
/// Gets or sets a boolean value that indicates whether the OpenTelemetry tracing is disabled or not.
/// </summary>
/// <value>
/// The default value is <see langword="false"/>.
/// </value>
public bool DisableTracing { get; set; }

void IConnectionStringSettings.ParseConnectionString(string? connectionString)
{
if (!string.IsNullOrEmpty(connectionString) &&
Uri.TryCreate(connectionString, UriKind.Absolute, out var uri))
{
Endpoint = uri;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"definitions": {
"logLevel": {
"properties": {
"Microsoft.Extensions.Configuration.AzureAppConfiguration.Refresh": {
"$ref": "#/definitions/logLevelThreshold"
}
}
}
},
"type": "object",
"properties": {
"Aspire": {
"type": "object",
"properties": {
"Azure": {
"type": "object",
"properties": {
"AppConfiguration": {
"type": "object",
"properties": {
"DisableTracing": {
"type": "boolean",
"description": "Gets or sets a boolean value that indicates whether the OpenTelemetry tracing is disabled or not.",
"default": false
},
"Endpoint": {
"type": "string",
"format": "uri",
"description": "A 'System.Uri' to the App Config store on which the client operates. Appears as \"Endpoint\" in the Azure portal. This is likely to be similar to \"https://{store_name}.azconfig.io\"."
}
},
"description": "Provides the client configuration settings for connecting to Azure App Configuration."
}
}
}
}
}
}
}
Loading