Skip to content

Commit cf36cd7

Browse files
Merge pull request #296717 from amerjusupovic/ajusupovic/ute-dotnetprovider-apis
Update configuration refresh examples for .NET
2 parents c9b739c + c96e9ea commit cf36cd7

6 files changed

+65
-64
lines changed

articles/azure-app-configuration/enable-dynamic-configuration-aspnet-core.md

+10-19
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ In this tutorial, you learn how to:
2525

2626
Finish the quickstart: [Create an ASP.NET Core app with App Configuration](./quickstart-aspnet-core-app.md).
2727

28-
## Add a sentinel key
29-
30-
A *sentinel key* is a key that you update after you complete the change of all other keys. Your app monitors the sentinel key. When a change is detected, your app refreshes all configuration values. This approach helps to ensure the consistency of configuration in your app and reduces the overall number of requests made to your App Configuration store, compared to monitoring all keys for changes.
31-
32-
1. In the Azure portal, open your App Configuration store and select **Configuration Explorer > Create > Key-value**.
33-
1. For **Key**, enter *TestApp:Settings:Sentinel*. For **Value**, enter 1. Leave **Label** and **Content type** blank.
34-
1. Select **Apply**.
35-
3628
## Reload data from App Configuration
3729

3830
1. Open *Program.cs*, and update the `AddAzureAppConfiguration` method you added during the quickstart. You can connect to App Configuration using either Microsoft Entra ID (recommended) or a connection string. The following code snippet demonstrates using Microsoft Entra ID.
@@ -44,20 +36,20 @@ A *sentinel key* is a key that you update after you complete the change of all o
4436
builder.Configuration.AddAzureAppConfiguration(options =>
4537
{
4638
options.Connect(new Uri(endpoint), new DefaultAzureCredential())
47-
// Load all keys that start with `TestApp:` and have no label
48-
.Select("TestApp:*", LabelFilter.Null)
49-
// Configure to reload configuration if the registered sentinel key is modified
50-
.ConfigureRefresh(refreshOptions =>
51-
refreshOptions.Register("TestApp:Settings:Sentinel", refreshAll: true));
39+
// Load all keys that start with `TestApp:` and have no label.
40+
.Select("TestApp:*", LabelFilter.Null)
41+
// Reload configuration if any selected key-values have changed.
42+
.ConfigureRefresh(refreshOptions =>
43+
refreshOptions.RegisterAll());
5244
});
5345
```
5446

5547
The `Select` method is used to load all key-values whose key name starts with *TestApp:* and that have *no label*. You can call the `Select` method more than once to load configurations with different prefixes or labels. If you share one App Configuration store with multiple apps, this approach helps load configuration only relevant to your current app instead of loading everything from your store.
5648

57-
In the `ConfigureRefresh` method, you register keys you want to monitor for changes in your App Configuration store. The `refreshAll` parameter to the `Register` method indicates that all configurations you specified by the `Select` method will be reloaded if the registered key changes.
49+
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). For more information about monitoring configuration changes, see [Best practices for configuration refresh](./howto-best-practices.md#configuration-refresh).
5850

5951
> [!TIP]
60-
> You can add a call to the `refreshOptions.SetCacheExpiration` method to specify the minimum time between configuration refreshes. In this example, you use the default value of 30 seconds. Adjust to a higher value if you need to reduce the number of requests made to your App Configuration store.
52+
> You can add a call to the `refreshOptions.SetRefreshInterval` method to specify the minimum time between configuration refreshes. In this example, you use the default value of 30 seconds. Adjust to a higher value if you need to reduce the number of requests made to your App Configuration store.
6153

6254
1. Add Azure App Configuration middleware to the service collection of your app.
6355

@@ -108,7 +100,7 @@ You've set up your app to use the [options pattern in ASP.NET Core](/aspnet/core
108100

109101
## Request-driven configuration refresh
110102

111-
The configuration refresh is triggered by the incoming requests to your web app. No refresh will occur if your app is idle. When your app is active, the App Configuration middleware monitors the sentinel key, or any other keys you registered for refreshing in the `ConfigureRefresh` call. The middleware is triggered upon every incoming request to your app. However, the middleware will only send requests to check the value in App Configuration when the cache expiration time you set has passed.
103+
The configuration refresh is triggered by the incoming requests to your web app. No refresh will occur if your app is idle. When your app is active, the App Configuration middleware monitors any keys you registered for refreshing in the `ConfigureRefresh` call. The middleware is triggered upon every incoming request to your app. However, the middleware will only send requests to check the value in App Configuration when the refresh interval you set has passed.
112104

113105
- If a request to App Configuration for change detection fails, your app will continue to use the cached configuration. New attempts to check for changes will be made periodically while there are new incoming requests to your app.
114106
- The configuration refresh happens asynchronously to the processing of your app's incoming requests. It will not block or slow down the incoming request that triggered the refresh. The request that triggered the refresh may not get the updated configuration values, but later requests will get new configuration values.
@@ -134,16 +126,15 @@ The configuration refresh is triggered by the incoming requests to your web app.
134126

135127
1. Sign in to the [Azure portal](https://portal.azure.com). Select **All resources**, and select the App Configuration store that you created in the quickstart.
136128
137-
1. Select **Configuration explorer**, and update the values of the following keys. Remember to update the sentinel key at last.
129+
1. Select **Configuration explorer**, and update the values of the following keys.
138130

139131
| Key | Value |
140132
|---|---|
141133
| TestApp:Settings:BackgroundColor | green |
142134
| TestApp:Settings:FontColor | lightGray |
143135
| TestApp:Settings:Message | Data from Azure App Configuration - now with live updates! |
144-
| TestApp:Settings:Sentinel | 2 |
145136

146-
1. Refresh the browser a few times. When the cache expires after 30 seconds, the page shows with updated content.
137+
1. Refresh the browser a few times. When the refresh interval elapses after 30 seconds, the page shows with updated content.
147138

148139
![Launching updated quickstart app locally](./media/quickstarts/aspnet-core-app-launch-local-after.png)
149140

articles/azure-app-configuration/enable-dynamic-configuration-aspnet-netfx.md

+12-14
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ Add the following key-values to the App Configuration store and leave **Label**
3838
| *TestApp:Settings:FontColor* | *Black* |
3939
| *TestApp:Settings:FontSize* | *40* |
4040
| *TestApp:Settings:Message* | *Data from Azure App Configuration* |
41-
| *TestApp:Settings:Sentinel* | *v1* |
4241

4342
## Create an ASP.NET Web Application
4443

@@ -102,11 +101,11 @@ Add the following key-values to the App Configuration store and leave **Label**
102101
options.Connect(new Uri(endpoint), new DefaultAzureCredential())
103102
// Load all keys that start with `TestApp:` and have no label.
104103
.Select("TestApp:*")
105-
// Configure to reload configuration if the registered key 'TestApp:Settings:Sentinel' is modified.
104+
// Reload configuration if any selected key-values have changed.
106105
.ConfigureRefresh(refresh =>
107106
{
108-
refresh.Register("TestApp:Settings:Sentinel", refreshAll:true)
109-
.SetCacheExpiration(new TimeSpan(0, 5, 0));
107+
refresh.RegisterAll()
108+
.SetRefreshInterval(new TimeSpan(0, 5, 0));
110109
});
111110
_configurationRefresher = options.GetRefresher();
112111
});
@@ -126,11 +125,11 @@ Add the following key-values to the App Configuration store and leave **Label**
126125
options.Connect(Environment.GetEnvironmentVariable("ConnectionString"))
127126
// Load all keys that start with `TestApp:` and have no label.
128127
.Select("TestApp:*")
129-
// Configure to reload configuration if the registered key 'TestApp:Settings:Sentinel' is modified.
128+
// Reload configuration if any selected key-values have changed.
130129
.ConfigureRefresh(refresh =>
131130
{
132-
refresh.Register("TestApp:Settings:Sentinel", refreshAll:true)
133-
.SetCacheExpiration(new TimeSpan(0, 5, 0));
131+
refresh.RegisterAll()
132+
.SetRefreshInterval(new TimeSpan(0, 5, 0));
134133
});
135134
_configurationRefresher = options.GetRefresher();
136135
});
@@ -142,9 +141,9 @@ Add the following key-values to the App Configuration store and leave **Label**
142141

143142
The `Application_Start` method is called upon the first request to your web application. It is called only once during the application's life cycle. As such it is a good place to initialize your `IConfiguration` object and load data from App Configuration.
144143

145-
In the `ConfigureRefresh` method, a key within your App Configuration store is registered for change monitoring. The `refreshAll` parameter to the `Register` method indicates that all configuration values should be refreshed if the registered key changes. In this example, the key *TestApp:Settings:Sentinel* is a *sentinel key* that you update after you complete the change of all other keys. When a change is detected, your application refreshes all configuration values. This approach helps to ensure the consistency of configuration in your application compared to monitoring all keys for changes.
144+
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). For more information about monitoring configuration changes, see [Best practices for configuration refresh](./howto-best-practices.md#configuration-refresh).
146145

147-
The `SetCacheExpiration` method specifies the minimum time that must elapse before a new request is made to App Configuration to check for any configuration changes. In this example, you override the default expiration time of 30 seconds, specifying a time of 5 minutes instead. It reduces the potential number of requests made to your App Configuration store.
146+
The `SetRefreshInterval` method specifies the minimum time that must elapse before a new request is made to App Configuration to check for any configuration changes. In this example, you override the default expiration time of 30 seconds, specifying a time of 5 minutes instead. It reduces the potential number of requests made to your App Configuration store.
148147

149148

150149
1. Add an `Application_BeginRequest` method to the `Global` class. If the method already exists, add the following code to it.
@@ -156,9 +155,9 @@ Add the following key-values to the App Configuration store and leave **Label**
156155
```
157156
Calling the `ConfigureRefresh` method alone won't cause the configuration to refresh automatically. You call the `TryRefreshAsync` method at the beginning of every request to signal a refresh. This design ensures your application only sends requests to App Configuration when it is actively receiving requests.
158157

159-
Calling `TryRefreshAsync` is a no-op before the configured cache expiration time elapses, so its performance impact is minimal. When a request is made to App Configuration, as you don't wait on the task, the configuration is refreshed asynchronously without blocking the execution of the current request. The current request may not get the updated configuration values, but subsequent requests will do.
158+
Calling `TryRefreshAsync` is a no-op before the configured refresh interval elapses, so its performance impact is minimal. When a request is made to App Configuration, as you don't wait on the task, the configuration is refreshed asynchronously without blocking the execution of the current request. The current request may not get the updated configuration values, but subsequent requests will do.
160159

161-
If the call `TryRefreshAsync` fails for any reason, your application will continue to use the cached configuration. Another attempt will be made when the configured cache expiration time has passed again, and the `TryRefreshAsync` call is triggered by a new request to your application.
160+
If the call `TryRefreshAsync` 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 again, and the `TryRefreshAsync` call is triggered by a new request to your application.
162161

163162
## Use the latest configuration data
164163

@@ -261,16 +260,15 @@ Add the following key-values to the App Configuration store and leave **Label**
261260

262261
![App launch local](./media/dotnet-fx-web-app-launch.png)
263262

264-
1. In the Azure portal, navigate to the **Configuration explorer** of your App Configuration store, and update the value of the following keys. Remember to update the sentinel key *TestApp:Settings:Sentinel* at last.
263+
1. In the Azure portal, navigate to the **Configuration explorer** of your App Configuration store, and update the value of the following keys.
265264

266265
| Key | Value |
267266
|------------------------------------|--------------------------------------------------------------|
268267
| *TestApp:Settings:BackgroundColor* | *Green* |
269268
| *TestApp:Settings:FontColor* | *LightGray* |
270269
| *TestApp:Settings:Message* | *Data from Azure App Configuration - now with live updates!* |
271-
| *TestApp:Settings:Sentinel* | *v2* |
272270

273-
1. Refresh the browser page to see the new configuration settings. You may need to refresh more than once for the changes to be reflected or change your cache expiration time to less than 5 minutes.
271+
1. Refresh the browser page to see the new configuration settings. You may need to refresh more than once for the changes to be reflected or change your refresh interval to less than 5 minutes.
274272

275273
![App refresh local](./media/dotnet-fx-web-app-refresh.png)
276274

0 commit comments

Comments
 (0)