-
Notifications
You must be signed in to change notification settings - Fork 644
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
sebastienros
merged 22 commits into
dotnet:main
from
zhiyuanliang-ms:zhiyuanliang/app-config-provider-component
May 12, 2025
Merged
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
ce47984
add app configuration provider as an aspire component
zhiyuanliang-ms 13ac167
update
zhiyuanliang-ms 1f1a79f
revert unintended change
zhiyuanliang-ms 5f7b39e
update comment typo
zhiyuanliang-ms 7023029
merge main
zhiyuanliang-ms 8eefef1
resolve comments
zhiyuanliang-ms e42e3d1
update
zhiyuanliang-ms efca902
update
zhiyuanliang-ms 9fa781b
merge main
zhiyuanliang-ms 74b7956
remove all tracing related code
zhiyuanliang-ms 3adaa0f
update readme
zhiyuanliang-ms 60faaef
update
zhiyuanliang-ms aaed55f
move Optional parameter to AzureAppConfigurationSettings
zhiyuanliang-ms c4d23ea
resolve merge conflict
zhiyuanliang-ms 2b6d013
upgrade app config package version
zhiyuanliang-ms ec6a5df
revert unintended change
zhiyuanliang-ms 2fe8a08
change package name to Aspire.Microsoft.Extensions.Configuration.Azur…
zhiyuanliang-ms 9179140
Update telemetry.md
sebastienros d8c2737
Update configuration sectopm
sebastienros 1349c14
Fix json format
sebastienros b6e7a38
Simplify sample in readme
sebastienros 3bfd79e
Merge branch 'main' into zhiyuanliang/app-config-provider-component
sebastienros File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/Components/Aspire.Azure.AppConfiguration/Aspire.Azure.AppConfiguration.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
zhiyuanliang-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<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" /> | ||
zhiyuanliang-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" /> | ||
<PackageReference Include="OpenTelemetry.Extensions.Hosting" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" /> | ||
sebastienros marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</ItemGroup> | ||
|
||
</Project> |
117 changes: 117 additions & 0 deletions
117
src/Components/Aspire.Azure.AppConfiguration/AspireAppConfigurationExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// 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; | ||
zhiyuanliang-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// <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> | ||
zhiyuanliang-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// <remarks>Reads the configuration from "Aspire:Azure:Data:AppConfiguration" section.</remarks> | ||
zhiyuanliang-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// <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); | ||
|
||
AzureAppConfigurationSettings settings = GetSettings(builder.Configuration, connectionName, configureSettings); | ||
|
||
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"])); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Adds the Azure App Configuration to be configuration values in the <paramref name="configurationManager"/>. | ||
/// </summary> | ||
/// <param name="configurationManager">The <see cref="IConfigurationManager"/> to add the secrets 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:Data:AppConfiguration" section.</remarks> | ||
zhiyuanliang-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// <exception cref="InvalidOperationException">Thrown when mandatory <see cref="AzureAppConfigurationSettings.Endpoint"/> is not provided.</exception> | ||
public static IConfigurationBuilder AddAzureAppConfiguration( | ||
this IConfigurationManager configurationManager, | ||
zhiyuanliang-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
string connectionName, | ||
Action<AzureAppConfigurationSettings>? configureSettings = null, | ||
Action<AzureAppConfigurationOptions>? configureOptions = null, | ||
bool optional = false) | ||
{ | ||
ArgumentNullException.ThrowIfNull(configurationManager); | ||
ArgumentException.ThrowIfNullOrEmpty(connectionName); | ||
|
||
AzureAppConfigurationSettings settings = GetSettings(configurationManager, connectionName, configureSettings); | ||
|
||
return configurationManager.AddAzureAppConfiguration( | ||
options => | ||
{ | ||
options.Connect(settings.Endpoint, settings.Credential ?? new DefaultAzureCredential()); | ||
configureOptions?.Invoke(options); | ||
}, | ||
optional); | ||
} | ||
|
||
private static AzureAppConfigurationSettings GetSettings( | ||
IConfiguration configuration, | ||
string connectionName, | ||
Action<AzureAppConfigurationSettings>? configureSettings) | ||
{ | ||
IConfigurationSection configSection = configuration.GetSection(DefaultConfigSectionName); | ||
|
||
var settings = new AzureAppConfigurationSettings(); | ||
configSection.Bind(settings); | ||
|
||
if (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."); | ||
} | ||
|
||
return settings; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Components/Aspire.Azure.AppConfiguration/AssemblyInfo.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")] |
41 changes: 41 additions & 0 deletions
41
src/Components/Aspire.Azure.AppConfiguration/AzureAppConfigurationSettings.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
zhiyuanliang-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
/// <summary> | ||
/// A <see cref="Uri"/> to the App Config store on which the client operates. Appears as "Endpoint" in the Azure portal. | ||
zhiyuanliang-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// 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; | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/Components/Aspire.Azure.AppConfiguration/ConfigurationSchema.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.