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/enable-dynamic-configuration-dotnet-core.md
+50-10Lines changed: 50 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
-
title: "Tutorial: Use dynamic configuration in a .NET Core app"
2
+
title: "Tutorial: Use dynamic configuration in a .NET app"
3
3
titleSuffix: Azure App Configuration
4
-
description: In this tutorial, you learn how to dynamically update the configuration data for .NET Core apps
4
+
description: In this tutorial, you learn how to dynamically update the configuration data for .NET apps
5
5
services: azure-app-configuration
6
6
documentationcenter: ''
7
7
author: mcleanbyron
@@ -14,31 +14,70 @@ ms.workload: tbd
14
14
ms.devlang: csharp
15
15
ms.custom: devx-track-csharp, devx-track-dotnet
16
16
ms.topic: tutorial
17
-
ms.date: 07/01/2019
17
+
ms.date: 07/11/2023
18
18
ms.author: mcleans
19
19
#Customer intent: I want to dynamically update my app to use the latest configuration data in App Configuration.
20
20
---
21
-
# Tutorial: Use dynamic configuration in a .NET Core app
21
+
# Tutorial: Use dynamic configuration in a .NET app
22
22
23
-
The App Configuration .NET provider library supports updating configuration on demand without causing an application to restart. This tutorial shows how you can implement dynamic configuration updates in your code. It builds on the app introduced in the quickstart. You should finish [Create a .NET Core app with App Configuration](./quickstart-dotnet-core-app.md) before continuing.
23
+
The App Configuration .NET provider library supports updating configuration on demand without causing an application to restart. This tutorial shows how you can implement dynamic configuration updates in your code. It builds on the app introduced in the quickstart. You should finish [Create a .NET app with App Configuration](./quickstart-dotnet-core-app.md) before continuing.
24
24
25
25
You can use any code editor to do the steps in this tutorial. [Visual Studio Code](https://code.visualstudio.com/) is an excellent option that's available on the Windows, macOS, and Linux platforms.
26
26
27
27
In this tutorial, you learn how to:
28
28
29
29
> [!div class="checklist"]
30
-
> * Set up your .NET Core app to update its configuration in response to changes in an App Configuration store.
30
+
> * Set up your .NET app to update its configuration in response to changes in an App Configuration store.
31
31
> * Consume the latest configuration in your application.
In the `ConfigureRefresh` method, a key within your App Configuration store is registered for change monitoring. The `Register` method has an optional boolean parameter `refreshAll` that can be used to indicate whether all configuration values should be refreshed if the registered key changes. In this example, only the key *TestApp:Settings:Message* will be refreshed. 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 10 seconds instead for demonstration purposes.
90
130
91
-
Calling the `ConfigureRefresh` method alone won't cause the configuration to refresh automatically. You call the `TryRefreshAsync` method from the interface `IConfigurationRefresher` to trigger a refresh. This design is to avoid phantom requests sent to App Configuration even when your application is idle. You will want to include the `TryRefreshAsync` call where you consider your application active. For example, it can be when you process an incoming message, an order, or an iteration of a complex task. It can also be in a timer if your application is active all the time. In this example, you call `TryRefreshAsync` every time you press the Enter key. Note that, even 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 and the `TryRefreshAsync` call is triggered by your application activity again. Calling `TryRefreshAsync` is a no-op before the configured cache expiration time elapses, so its performance impact is minimal, even if it's called frequently.
131
+
Calling the `ConfigureRefresh` method alone won't cause the configuration to refresh automatically. You call the `TryRefreshAsync` method from the interface `IConfigurationRefresher` to trigger a refresh. This design is to avoid phantom requests sent to App Configuration even when your application is idle. You'll want to include the `TryRefreshAsync` call where you consider your application active. For example, it can be when you process an incoming message, an order, or an iteration of a complex task. It can also be in a timer if your application is active all the time. In this example, you call `TryRefreshAsync` every time you press the Enter key. Even if the call `TryRefreshAsync` fails for any reason, your application continues to use the cached configuration. Another attempt is made when the configured cache expiration time has passed and the `TryRefreshAsync` call is triggered by your application activity again. Calling `TryRefreshAsync` is a no-op before the configured cache expiration time elapses, so its performance impact is minimal, even if it's called frequently.
92
132
93
133
## Build and run the app locally
94
134
@@ -186,7 +226,7 @@ Logs are output upon configuration refresh and contain detailed information on k
186
226
187
227
## Next steps
188
228
189
-
In this tutorial, you enabled your .NET Core app to dynamically refresh configuration settings from App Configuration. To learn how to use an Azure managed identity to streamline the access to App Configuration, continue to the next tutorial.
229
+
In this tutorial, you enabled your .NET app to dynamically refresh configuration settings from App Configuration. To learn how to use an Azure managed identity to streamline the access to App Configuration, continue to the next tutorial.
# Use managed identities to access App Configuration
14
14
15
15
Azure Active Directory [managed identities](../active-directory/managed-identities-azure-resources/overview.md) simplify secrets management for your cloud application. With a managed identity, your code can use the service principal created for the Azure service it runs on. You use a managed identity instead of a separate credential stored in Azure Key Vault or a local connection string.
16
16
17
-
Azure App Configuration and its .NET Core, .NET Framework, and Java Spring client libraries have managed identity support built into them. Although you aren't required to use it, the managed identity eliminates the need for an access token that contains secrets. Your code can access the App Configuration store using only the service endpoint. You can embed this URL in your code directly without exposing any secret.
17
+
Azure App Configuration and its .NET, .NET Framework, and Java Spring client libraries have managed identity support built into them. Although you aren't required to use it, the managed identity eliminates the need for an access token that contains secrets. Your code can access the App Configuration store using only the service endpoint. You can embed this URL in your code directly without exposing any secret.
18
18
19
19
:::zone target="docs" pivot="framework-dotnet"
20
20
@@ -45,7 +45,7 @@ To complete this tutorial, you must have:
@@ -128,24 +128,17 @@ The following steps describe how to assign the App Configuration Data Reader rol
128
128
using Azure.Identity;
129
129
```
130
130
131
-
1. If you wish to access only values stored directly in App Configuration, update the `CreateWebHostBuilder` method by replacing the `config.AddAzureAppConfiguration()` method (this method is found in the `Microsoft.Azure.AppConfiguration.AspNetCore` package).
131
+
1. To access values stored in App Configuration, update the `Builder` configuration to use the the `AddAzureAppConfiguration()` method.
132
132
133
-
> [!IMPORTANT]
134
-
>`CreateHostBuilder` replaces `CreateWebHostBuilder`in .NET Core 3.0. Select the correct syntax based on your environment.
135
-
136
-
### [.NET Core 5.x](#tab/core5x)
133
+
### [.NET 6.0+](#tab/core6x)
137
134
138
135
```csharp
139
-
public static IHostBuilder CreateHostBuilder(string[] args) =>
options.Connect(new Uri(settings["AppConfig:Endpoint"]), new ManagedIdentityCredential()));
176
-
})
177
-
.UseStartup<Startup>();
178
-
```
179
-
180
159
---
181
160
182
161
> [!NOTE]
183
162
> If you want to use a **user-assigned managed identity**, be sure to specify the `clientId` when creating the [ManagedIdentityCredential](/dotnet/api/azure.identity.managedidentitycredential).
184
163
>```csharp
185
-
>config.AddAzureAppConfiguration(options =>
186
-
> {
187
-
> options.Connect(new Uri(settings["AppConfig:Endpoint"]), new ManagedIdentityCredential("<your_clientId>"))
188
-
> });
164
+
>new ManagedIdentityCredential("<your_clientId>")
189
165
>```
190
166
>As explained in the [Managed Identities forAzure resources FAQs](../active-directory/managed-identities-azure-resources/known-issues.md), there is a default way to resolve which managed identity is used. In this case, the Azure Identity library enforces you to specify the desired identity to avoid possible runtime issuesin the future. For instance, if a new user-assigned managed identity is added or if the system-assigned managed identity is enabled. So, you will need to specify the `clientId` even if only one user-assigned managed identity is defined, and there is no system-assigned managed identity.
> The preceding code snippet uses the Secret Manager tool to load App Configuration connection string. For information storing the connection string using the Secret Manager, see [Quickstart for Azure App Configuration with ASP.NET Core](quickstart-aspnet-core-app.md).
0 commit comments