Skip to content

Commit 29b014e

Browse files
update
1 parent 5088792 commit 29b014e

File tree

2 files changed

+69
-22
lines changed

2 files changed

+69
-22
lines changed

articles/azure-app-configuration/reference-dotnet-provider.md

Lines changed: 68 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ ms.devlang: csharp
1010
ms.custom: devx-track-csharp
1111
ms.topic: tutorial
1212
ms.date: 04/29/2025
13-
#Customer intent: I want to learn how to use Azure App Configuration .NET client library.
13+
#Customer intent: I want to learn how to use the Azure App Configuration .NET configuration provider library.
1414
---
1515

1616
# .NET Configuration Provider
1717

1818
[![Microsoft.Extensions.Configuration.AzureAppConfiguration](https://img.shields.io/nuget/v/Microsoft.Extensions.Configuration.AzureAppConfiguration?label=Microsoft.Extensions.Configuration.AzureAppConfiguration)](https://www.nuget.org/packages/Microsoft.Extensions.Configuration.AzureAppConfiguration)
1919

20-
Azure App Configuration is a managed service that helps developers centralize their application configurations simply and securely. The .NET configuration provider library enables loading configuration from an Azure App Configuration store in a managed way. This client library adds additional [functionality](./configuration-provider-overview.md#feature-development-status) above the Azure SDK for .NET.
20+
Azure App Configuration is a managed service that helps developers centralize their application configurations simply and securely. The .NET configuration provider library enables loading configuration from an Azure App Configuration store in a managed way. This client library adds additional [functionality](./configuration-provider-overview.md#feature-development-status) on top of the Azure SDK for .NET.
2121

2222
## Load configuration
2323

@@ -37,7 +37,7 @@ To connect to your Azure App Configuration store, call the `Connect` method on t
3737

3838
### [Microsoft Entra ID](#tab/entra-id)
3939

40-
You use the `DefaultAzureCredential` to authenticate to your App Configuration store. Follow the [instructions](./concept-enable-rbac.md#authentication-with-token-credentials) to assign your credential the **App Configuration Data Reader** role.
40+
You can use the `DefaultAzureCredential`, or any other [token credential implementation](/dotnet/api/azure.identity.defaultazurecredential), to authenticate to your App Configuration store. Follow the [instructions](./concept-enable-rbac.md#authentication-with-token-credentials) to assign your credential the **App Configuration Data Reader** role.
4141

4242
```csharp
4343
using Microsoft.Extensions.Configuration;
@@ -47,7 +47,7 @@ using Azure.Identity;
4747
var builder = new ConfigurationBuilder();
4848
builder.AddAzureAppConfiguration(options =>
4949
{
50-
string endpoint = Environment.GetEnvironmentVariable("Endpoint");
50+
string endpoint = Environment.GetEnvironmentVariable("AppConfigurationEndpoint");
5151
options.Connect(new Uri(endpoint), new DefaultAzureCredential());
5252
});
5353

@@ -153,13 +153,15 @@ public class Settings
153153
builder.Services.Configure<Settings>(builder.Configuration.GetSection("TestApp:Settings"));
154154
```
155155

156+
For more information about options pattern in .NET, go to the [documentation](dotnet/core/extensions/options).
157+
156158
### JSON content type handling
157159

158-
You can create JSON key-values in App Configuration. For more information, go to [Use content type to store JSON key-values in App Configuration](./howto-leverage-json-content-type.md).
160+
You can create JSON key-values in App Configuration. When a key-value with the content type `"application/json"` is read, the configuration provider will flatten it into individual settings inside of `IConfiguration`. For more information, go to [Use content type to store JSON key-values in App Configuration](./howto-leverage-json-content-type.md).
159161

160162
### Load specific key-values using selectors
161163

162-
By default, the configuration provider loads all key-values with no label from the App Configuration. You can selectively load key-values from your App Configuration store by calling `Select` method on `AzureAppConfigurationOptions`.
164+
By default, the configuration provider loads all key-values with no label from App Configuration. You can selectively load key-values from your App Configuration store by calling the `Select` method on `AzureAppConfigurationOptions`.
163165

164166
```csharp
165167
builder.AddAzureAppConfiguration(options =>
@@ -239,11 +241,7 @@ builder.Configuration.AddAzureAppConfiguration(options =>
239241
240242
## Configuration refresh
241243

242-
Dynamic refresh for the configurations lets you pull their latest values from the App Configuration store without having to restart the application. You can call the `ConfigureRefresh` method to configure the key-value refresh.
243-
244-
Inside the `ConfigureRefresh` method, you call the `RegisterAll` method to instruct the App Configuration provider to reload the entire configuration whenever it detects a change in any of the selected key-values (those starting with TestApp: and having no label).
245-
246-
You can add a call to the `SetRefreshInterval` method to specify the minimum time between configuration refreshes. If not set, the default refresh interval is 30 seconds.
244+
Configuring refresh enables the application to pull the latest values from the App Configuration store without having to restart. You can call the `ConfigureRefresh` method to configure the key-value refresh.
247245

248246
```csharp
249247
builder.Configuration.AddAzureAppConfiguration(options =>
@@ -254,12 +252,16 @@ builder.Configuration.AddAzureAppConfiguration(options =>
254252
.ConfigureRefresh(refreshOptions => {
255253
// Trigger full configuration refresh when any selected key changes.
256254
refreshOptions.RegisterAll()
257-
// Check for changes no more often than every 10 seconds
258-
.SetRefreshInterval(TimeSpan.FromSeconds(10));
255+
// Check for changes no more often than every 60 seconds
256+
.SetRefreshInterval(TimeSpan.FromSeconds(60));
259257
});
260258
});
261259
```
262260

261+
Inside the `ConfigureRefresh` method, you call the `RegisterAll` method to instruct the App Configuration provider to reload configuration whenever it detects a change in any of the selected key-values (those starting with TestApp: and having no label).
262+
263+
You can add a call to the `SetRefreshInterval` method to specify the minimum time between configuration refreshes. If not set, the default refresh interval is 30 seconds.
264+
263265
### Trigger refresh
264266

265267
To trigger refresh, you need to call the `TryRefreshAsync` method of the `IConfigurationRefresher`. Azure App Configuration provides several patterns for implementation depending on your application architecture.
@@ -305,7 +307,7 @@ builder.Configuration.AddAzureAppConfiguration(options =>
305307
.ConfigureRefresh(refreshOptions =>
306308
{
307309
refreshOptions.RegisterAll()
308-
.SetRefreshInterval(TimeSpan.FromSeconds(10));
310+
.SetRefreshInterval(TimeSpan.FromSeconds(60));
309311
})
310312
});
311313

@@ -350,6 +352,21 @@ dotnet add package Microsoft.Azure.AppConfiguration.AspNetCore
350352
The middleware calls the `TryRefreshAsync` method on the registered `IConfigurationRefresher` when there are new incoming requests to your application.
351353

352354
```csharp
355+
builder.Configuration.AddAzureAppConfiguration(options =>
356+
{
357+
options.Connect(new Uri(appConfigEndpoint), new DefaultAzureCredential())
358+
.ConfigureRefresh(refreshOptions =>
359+
{
360+
refreshOptions.RegisterAll()
361+
.SetRefreshInterval(TimeSpan.FromSeconds(60));
362+
})
363+
});
364+
365+
// Add Azure App Configuration middleware to the container of services.
366+
builder.Services.AddAzureAppConfiguration();
367+
368+
...
369+
353370
var app = builder.Build();
354371

355372
// Call the app.UseAzureAppConfiguration() method as early as appropriate in your request pipeline so another middleware doesn't skip it
@@ -362,7 +379,7 @@ app.UseRouting();
362379
```
363380

364381
> [!NOTE]
365-
> Even if the refresh call fails for any reason, your application continues to use the cached configuration. Another attempt is made when the configured refresh interval has passed and the refresh call is triggered by your application activity. Calling refresh is a no-op before the configured refresh interval elapses, so its performance impact is minimal even if it's called frequently.
382+
> Even if the refresh call fails for any reason, your application continues to use the cached configuration. Another attempt is made after a short period based on your application activity. Calling refresh is a no-op before the configured refresh interval elapses, so its performance impact is minimal even if it's called frequently.
366383
367384
### Refresh on sentinel key
368385

@@ -399,8 +416,8 @@ builder.Configuration.AddAzureAppConfiguration(options =>
399416
.UseFeatureFlags(featureFlagOptions => {
400417
// Load feature flags with prefix "TestApp:" and "dev" label
401418
featureFlagOptions.Select("TestApp:*", "dev")
402-
// Check for changes no more often than every 10 seconds
403-
.SetRefreshInterval(TimeSpan.FromSeconds(10));
419+
// Check for changes no more often than every 60 seconds
420+
.SetRefreshInterval(TimeSpan.FromSeconds(60));
404421
});
405422
});
406423
```
@@ -411,7 +428,7 @@ Different from key-values, feature flags are automatically registered for refres
411428

412429
### Feature management
413430

414-
Feature management library provides a way to develop and expose application functionality based on feature flags. The feature management library is designed to work in conjunction with the configuration provider library. Install the [`Microsoft.FeatureManagement`](./feature-management-dotnet-reference.md) package:
431+
The feature management library provides a way to develop and expose application functionality based on feature flags. The feature management library is designed to work in conjunction with the configuration provider library. Install the [`Microsoft.FeatureManagement`](./feature-management-dotnet-reference.md) package:
415432

416433
```console
417434
dotnet add package Microsoft.FeatureManagement
@@ -472,7 +489,11 @@ The configuration provider library retrieves Key Vault references, just as it do
472489

473490
### Connect to Key Vault
474491

475-
You need to call the `ConfigureKeyVault` method to configure how to connect the Key Vault. You can register a specified `SecretClient` instance to use to resolve key vault references for secrets from associated key vault or set the credential used to authenticate to key vaults that have no registered `SecretClient`.
492+
You need to call the `ConfigureKeyVault` method to configure how to connect to Key Vault. The Azure App Configuration provider offers multiple ways to authenticate and access your Key Vault secrets.
493+
494+
#### 1. Register `SecretClient` instance
495+
496+
You can register specified `SecretClient` instances to use to resolve key vault references for secrets from associated key vault.
476497

477498
```csharp
478499
using Azure.Identity;
@@ -487,14 +508,34 @@ builder.Configuration.AddAzureAppConfiguration(options =>
487508
options.Connect(new Uri(appConfigEndpoint), new DefaultAzureCredential())
488509
.ConfigureKeyVault(kv =>
489510
{
490-
// Use DefaultAzureCredential to access Key Vault
491-
kv.SetCredential(new DefaultAzureCredential());
492511
// Register a SecretClient instance
493512
kv.Register(secretClient);
494513
});
495514
});
496515
```
497516

517+
#### 2. Use credential
518+
519+
You can set the credential used to authenticate to key vaults that have no registered `SecretClient`.
520+
521+
```csharp
522+
using Azure.Identity;
523+
524+
...
525+
526+
builder.Configuration.AddAzureAppConfiguration(options =>
527+
{
528+
options.Connect(new Uri(appConfigEndpoint), new DefaultAzureCredential())
529+
.ConfigureKeyVault(kv =>
530+
{
531+
// Use DefaultAzureCredential to access all Key Vaults
532+
kv.SetCredential(new DefaultAzureCredential());
533+
});
534+
});
535+
```
536+
537+
#### 3. Use custom secret resolver
538+
498539
You can also call `SetSecretResolver` to add a custom secret resolver which is used when no registered `SecretClient` is available or the provided credential fails to authenticate to Key Vault. This method accepts a delegate function that resolves a Key Vault URI to a secret value. The following example demonstrates using a secret resolver that retrieves a secret from environment variables in development and uses fallback values when it fails to get the secret from Key Vault.
499540

500541
```csharp
@@ -529,6 +570,12 @@ builder.Configuration.AddAzureAppConfiguration(options =>
529570
});
530571
```
531572

573+
> [!NOTE]
574+
> When resolving Key Vault references, the provider follows this order:
575+
> 1. Registered `SecretClient` instances
576+
> 1. Default credential
577+
> 1. Custom secret resolver
578+
532579
> [!IMPORTANT]
533580
> If your application loads key-values containing Key Vault references without proper Key Vault configuration, an **exception** will be thrown at startup. Ensure you've properly configured Key Vault access or secret resolver.
534581

articles/azure-app-configuration/reference-javascript-provider.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ const appConfig = await load(endpoint, credential, {
256256
selectors: [ { keyFilter: "*", labelFilter: "Prod" } ],
257257
refresh: {
258258
enabled: true, // enable refreshing feature flags
259-
refreshIntervalInMs: 10_000
259+
refreshIntervalInMs: 60_000
260260
}
261261
}
262262
});

0 commit comments

Comments
 (0)