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
Copy file name to clipboardExpand all lines: articles/azure-app-configuration/reference-dotnet-provider.md
+50-55Lines changed: 50 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -266,56 +266,58 @@ You can add a call to the `SetRefreshInterval` method to specify the minimum tim
266
266
267
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.
268
268
269
-
#### 1. Direct access
269
+
#### 1. Dependency injection
270
270
271
-
For applications not using dependency injection, you can obtain the refresher directly from the options:
271
+
For applications using dependency injection (including ASP.NET Core and background services), register the refresher service:
// Register refresher service with the DI container
285
+
builder.Services.AddAzureAppConfiguration();
286
+
```
289
287
290
-
// Later in your code, trigger refresh when needed
291
-
if (refresher!=null)
292
-
{
293
-
awaitrefresher.TryRefreshAsync()
294
-
}
288
+
`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.
For ASP.NET Core applications, you can use the `Microsoft.Azure.AppConfiguration.AspNetCore` package to achieve [request-driven configuration refresh](./enable-dynamic-configuration-aspnet-core#request-driven-configuration-refresh) with a built-in middleware.
300
293
301
-
For applications using dependency injection (including ASP.NET Core and Worker Services), register the refresher service:
After registering the service, call the `UseAzureAppConfiguration` to add the `AzureAppConfigurationRefreshMiddleware` to your application pipeline to automatically refresh configuration on incoming requests:
//Register refresher services with the DI container
303
+
//Call the AddAzureAppConfiguration to add refresher service to the DI container
315
304
builder.Services.AddAzureAppConfiguration();
305
+
306
+
varapp=builder.Build();
307
+
308
+
// Call the app.UseAzureAppConfiguration() method as early as appropriate in your request pipeline so another middleware doesn't skip it
309
+
app.UseAzureAppConfiguration();
310
+
311
+
// Continue with other middleware registration
312
+
app.UseRouting();
313
+
...
316
314
```
317
315
318
-
`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.
316
+
The `AzureAppConfigurationRefreshMiddleware` automatically checks for configuration changes at the configured refresh interval. This approach is efficient as it only refreshes when both conditions are met: an HTTP request is received and the refresh interval has elapsed.
317
+
318
+
#### Background services
319
+
320
+
For background services, you can inject the `IConfigurationRefresherProvider` service and manually refresh each of the registered refreshers.
319
321
320
322
```csharp
321
323
publicclassWorker : BackgroundService
@@ -341,41 +343,34 @@ public class Worker : BackgroundService
341
343
}
342
344
```
343
345
344
-
#### 3. ASP.NET Core
345
-
346
-
You can use the `Microsoft.Azure.AppConfiguration.AspNetCore` package to use the `AzureAppConfigurationRefreshMiddleware` to achieve the request-driven configuration refresh.
The middleware calls the `TryRefreshAsync` method on the registered `IConfigurationRefresher` when there are new incoming requests to your application.
348
+
For applications not using dependency injection, you can obtain the refresher directly from the options:
0 commit comments