You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
21
21
22
22
## Load configuration
23
23
@@ -37,7 +37,7 @@ To connect to your Azure App Configuration store, call the `Connect` method on t
37
37
38
38
### [Microsoft Entra ID](#tab/entra-id)
39
39
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.
For more information about options pattern in .NET, go to the [documentation](dotnet/core/extensions/options).
157
+
156
158
### JSON content type handling
157
159
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).
159
161
160
162
### Load specific key-values using selectors
161
163
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`.
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.
// Trigger full configuration refresh when any selected key changes.
256
254
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));
259
257
});
260
258
});
261
259
```
262
260
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
+
263
265
### Trigger refresh
264
266
265
267
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.
The middleware calls the `TryRefreshAsync` method on the registered `IConfigurationRefresher` when there are new incoming requests to your application.
// Add Azure App Configuration middleware to the container of services.
366
+
builder.Services.AddAzureAppConfiguration();
367
+
368
+
...
369
+
353
370
varapp=builder.Build();
354
371
355
372
// 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();
362
379
```
363
380
364
381
> [!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.
// Load feature flags with prefix "TestApp:" and "dev" label
401
418
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));
404
421
});
405
422
});
406
423
```
@@ -411,7 +428,7 @@ Different from key-values, feature flags are automatically registered for refres
411
428
412
429
### Feature management
413
430
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:
415
432
416
433
```console
417
434
dotnet add package Microsoft.FeatureManagement
@@ -472,7 +489,11 @@ The configuration provider library retrieves Key Vault references, just as it do
472
489
473
490
### Connect to Key Vault
474
491
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.
// Use DefaultAzureCredential to access all Key Vaults
532
+
kv.SetCredential(newDefaultAzureCredential());
533
+
});
534
+
});
535
+
```
536
+
537
+
#### 3. Use custom secret resolver
538
+
498
539
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.
> 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
+
532
579
> [!IMPORTANT]
533
580
> 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.
0 commit comments