Skip to content

Commit 8e7c922

Browse files
update
1 parent f718bff commit 8e7c922

File tree

1 file changed

+33
-22
lines changed

1 file changed

+33
-22
lines changed

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

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ You can create JSON key-values in App Configuration. For more information, go to
159159

160160
### Load specific key-values using selectors
161161

162-
By default, the configuration provider will load 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`.
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`.
163163

164164
```csharp
165165
builder.AddAzureAppConfiguration(options =>
@@ -181,7 +181,7 @@ The `Select` method takes two parameters, the first parameter is a key filter th
181181

182182
The key filter parameter determines which configuration keys to include:
183183

184-
- **Exact match**: Using a specific string will match only keys that exactly match the filter.
184+
- **Exact match**: Using a specific string matches only keys that exactly match the filter.
185185
- **Prefix match**: Adding an asterisk (`*`) at the end creates a prefix filter (e.g., `App:Settings:*` loads all keys starting with "App:Settings:").
186186
- **Multiple key selection**: Using a comma (`,`) allows selection of multiple explicit keys (e.g., `Key1,Key2,Key3`).
187187
- **Reserved characters**: The characters asterisk (`*`), comma (`,`), and backslash (`\`) are reserved and must be escaped with a backslash when used in key names (e.g. the key filter `a\\b\,\*c*` returns all key-values whose key starts with `a\b,*c`.).
@@ -191,7 +191,7 @@ The key filter parameter determines which configuration keys to include:
191191
192192
#### Label filter
193193

194-
The label filter parameter selects key-values with a specific label. If not specified, the built-in `LabelFilter.Null` will be used.
194+
The label filter parameter selects key-values with a specific label. If not specified, the built-in `LabelFilter.Null` is used.
195195

196196
> [!NOTE]
197197
> The characters asterisk (`*`) and comma (`,`), are not supported for label filter. Backslash (`\`) character is reserved and must be escaped using another backslash (`\`).
@@ -313,7 +313,7 @@ builder.Configuration.AddAzureAppConfiguration(options =>
313313
builder.Services.AddAzureAppConfiguration();
314314
```
315315

316-
The `builder.Services.AddAzureAppConfiguration()` add the `IConfigurationRefreshProvider` service to the DI container. It will give you the access to the refreshers of all Azure App Configuration sources in the application's configuration.
316+
`builder.Services.AddAzureAppConfiguration()` adds the `IConfigurationRefreshProvider` service to the DI container, which gives you access to the refreshers of all Azure App Configuration sources in the application's configuration.
317317

318318
```csharp
319319
public class Worker : BackgroundService
@@ -347,12 +347,12 @@ You can use the `Microsoft.Azure.AppConfiguration.AspNetCore` package to use the
347347
dotnet add package Microsoft.Azure.AppConfiguration.AspNetCore
348348
```
349349

350-
The middleware will call the `TryRefreshAsync` method on the registered `IConfigurationRefresher` when there are new incoming requests to your application.
350+
The middleware calls the `TryRefreshAsync` method on the registered `IConfigurationRefresher` when there are new incoming requests to your application.
351351

352352
```csharp
353353
var app = builder.Build();
354354

355-
// Call the app.UseAzureAppConfiguration() method as early as appropriate in your request pipeline so another middleware won't skip it
355+
// Call the app.UseAzureAppConfiguration() method as early as appropriate in your request pipeline so another middleware doesn't skip it
356356
app.UseAzureAppConfiguration();
357357

358358
// Continue with other middleware registration
@@ -362,11 +362,11 @@ app.UseRouting();
362362
```
363363

364364
> [!NOTE]
365-
> Even if the refresh call fails for any reason, your application will continue to use the cached configuration. Another attempt will be 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.
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.
366366
367367
### Refresh on sentinel key
368368

369-
A sentinel key is a key that you update after you complete the change of all other keys. The configuration provider will monitor the sentinel key instead of all selected key-values. When a change is detected, your app refreshes all configuration values.
369+
A sentinel key is a key that you update after you complete the change of all other keys. The configuration provider monitors the sentinel key instead of all selected key-values. When a change is detected, your app refreshes all configuration values.
370370

371371
This approach is useful when updating multiple key-values. By updating the sentinel key only after all other configuration changes are completed, you ensure your application reloads configuration just once, maintaining consistency.
372372

@@ -405,11 +405,11 @@ builder.Configuration.AddAzureAppConfiguration(options =>
405405
});
406406
```
407407

408-
Inside the `UseFeatureFlags` method, you call the `Select` method to selectively load feature flags. You can use [key filter](#key-filter) and [label filter](#label-filter) to select the feature flags you want to load. If no `Select` method is called, `UseFeatureFlags` will load all feature flags with no label by default.
408+
Inside the `UseFeatureFlags` method, you call the `Select` method to selectively load feature flags. You can use [key filter](#key-filter) and [label filter](#label-filter) to select the feature flags you want to load. If no `Select` method is called, `UseFeatureFlags` loads all feature flags with no label by default.
409409

410-
Different from key-values, feature flags will be automatically registered for refresh without requiring explicit `ConfigureRefresh` call. You can specify the minimum time between feature flag refreshes through the `SetRefreshInterval` method. The default refresh interval is 30 seconds.
410+
Different from key-values, feature flags are automatically registered for refresh without requiring explicit `ConfigureRefresh` call. You can specify the minimum time between feature flag refreshes through the `SetRefreshInterval` method. The default refresh interval is 30 seconds.
411411

412-
### Feature Management
412+
### Feature management
413413

414414
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:
415415

@@ -468,7 +468,7 @@ For more information about how to use the feature management library, go to the
468468

469469
Azure App Configuration supports referencing secrets stored in Azure Key Vault. In App Configuration, you can create keys that map to secrets stored in Key Vault. The secrets are securely stored in Key Vault, but can be accessed like any other configuration once loaded.
470470

471-
The configuration provider library retrieves Key Vault references, just as it does for any other keys stored in App Configuration. Because the client recognizes the keys as Key Vault references, they have a unique content-type, and the client will connect to Key Vault to retrieve their values for your application.
471+
The configuration provider library retrieves Key Vault references, just as it does for any other keys stored in App Configuration. Because the client recognizes the keys as Key Vault references, they have a unique content-type, and the client connects to Key Vault to retrieve their values for your application.
472472

473473
### Connect to Key Vault
474474

@@ -480,7 +480,7 @@ using Azure.Security.KeyVault.Secrets;
480480

481481
...
482482

483-
SecretClient secretClient = new SecretClient(new Uri(vaultUri), new DefaultAzureCredential());
483+
var secretClient = new SecretClient(new Uri(vaultUri), new DefaultAzureCredential());
484484

485485
builder.Configuration.AddAzureAppConfiguration(options =>
486486
{
@@ -495,9 +495,11 @@ builder.Configuration.AddAzureAppConfiguration(options =>
495495
});
496496
```
497497

498-
You can also call `SetSecretResolver` to add a custom secret resolver which will be 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 demostrates using a secret resolver to retrieve secret from environment variables in development.
498+
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 demostrates using a secret resolver to retrieve secret from environment variables in development and use fallback value when fail to get secret from the Key Vault.
499499

500500
```csharp
501+
var secretClient = new SecretClient(new Uri(vaultUri), new DefaultAzureCredential());
502+
501503
builder.Configuration.AddAzureAppConfiguration(options =>
502504
{
503505
options.Connect(new Uri(appConfigEndpoint), new DefaultAzureCredential())
@@ -508,21 +510,30 @@ builder.Configuration.AddAzureAppConfiguration(options =>
508510
{
509511
if (builder.Environment.IsDevelopment())
510512
{
511-
return Environment.GetEnvironmentVariable("KeyVaultSecret");
513+
return Environment.GetEnvironmentVariable("FALLBACK_SECRET_VALUE");
512514
}
513515

514-
var secretClient = new SecretClient(
515-
new Uri(secretUri.GetLeftPart(UriPartial.Authority)),
516-
new ManagedIdentityCredential());
517-
var secret = await secretClient.GetSecretAsync(secretName);
518-
return secret.Value;
516+
try
517+
{
518+
var secret = await secretClient.GetSecretAsync(secretName);
519+
return secret.Value;
520+
}
521+
catch (Exception ex)
522+
{
523+
logger.LogWarning($"Failed to retrieve secret from {secretUri}: {ex.Message}");
524+
525+
return Environment.GetEnvironmentVariable("FALLBACK_SECRET_VALUE");
526+
}
519527
});
520528
});
521529
});
522530
```
523531

524532
> [!IMPORTANT]
525-
> 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.
533+
> 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.
534+
535+
> [!TIP]
536+
> You can use a custom secret resolver to handle cases where Key Vault references are accidentally added to your App Configuration store. The resolver can provide fallback values, log warnings, or gracefully handle missing proper credential to access Key Vault instead of throwing exceptions.
526537
527538
### Key Vault secret refresh
528539

@@ -565,7 +576,7 @@ You can call `SelectSnapshot` to load key-values from a snapshot.
565576
builder.Configuration.AddAzureAppConfiguration(options =>
566577
{
567578
options.Connect(new Uri(appConfigEndpoint), new DefaultAzureCredential());
568-
// Select an existing snapshot by name. This will add all of the key-values from the snapshot to this application's configuration.
579+
// Select an existing snapshot by name. This adds all of the key-values and feature flags from the snapshot to this application's configuration.
569580
options.SelectSnapshot("SnapshotName");
570581
});
571582
```

0 commit comments

Comments
 (0)