Skip to content

Commit 95a0929

Browse files
committed
Add Entra ID tab
1 parent b3506e3 commit 95a0929

File tree

1 file changed

+54
-19
lines changed

1 file changed

+54
-19
lines changed

articles/azure-app-configuration/enable-dynamic-configuration-dotnet-background-service.md

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,35 @@ You use the [.NET command-line interface (CLI)](/dotnet/core/tools/) to create a
7070
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
7171
```
7272
73-
1. Connect to App Configuration.
73+
1. Connect to App Configuration using Microsoft Entra ID (recommended), or a connection string.
7474
75+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
76+
```csharp
77+
// Existing code in Program.cs
78+
// ... ...
79+
80+
var builder = Host.CreateApplicationBuilder(args);
81+
82+
builder.Configuration.AddAzureAppConfiguration(options =>
83+
{
84+
options.Connect(new DefaultAzureCredential())
85+
// Load all keys that start with `TestApp:`.
86+
.Select("TestApp:*")
87+
// Configure to reload the key 'TestApp:Settings:Message' if it is modified.
88+
.ConfigureRefresh(refreshOptions =>
89+
{
90+
refreshOptions.Register("TestApp:Settings:Message");
91+
});
92+
93+
// Register the refresher so that the Worker service can consume it through DI
94+
builder.Services.AddSingleton(options.GetRefresher());
95+
});
96+
97+
// The rest of existing code in Program.cs
98+
// ... ...
99+
```
100+
101+
### [Connection string](#tab/connection-string)
75102
```csharp
76103
// Existing code in Program.cs
77104
// ... ...
@@ -96,6 +123,7 @@ You use the [.NET command-line interface (CLI)](/dotnet/core/tools/) to create a
96123
// The rest of existing code in Program.cs
97124
// ... ...
98125
```
126+
---
99127
100128
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. All settings registered for refresh have a default cache expiration of 30 seconds before a new refresh is attempted. It can be updated by calling the `AzureAppConfigurationRefreshOptions.SetCacheExpiration` method.
101129
@@ -137,42 +165,49 @@ You use the [.NET command-line interface (CLI)](/dotnet/core/tools/) to create a
137165
138166
## Build and run the app locally
139167
140-
1. Set an environment variable named **ConnectionString**, and set it to the access key to your App Configuration store. At the command line, run the following command.
168+
1. Set an environment variable.
141169
142-
### [Windows command prompt](#tab/windowscommandprompt)
170+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
171+
Set the environment variable named **Endpoint** to the endpoint of your App Configuration store found under the *Overview* of your store in the Azure portal.
143172
144-
To build and run the app locally using the Windows command prompt, run the following command.
173+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
145174
146-
```console
147-
setx ConnectionString "connection-string-of-your-app-configuration-store"
175+
```cmd
176+
setx Endpoint "endpoint-of-your-app-configuration-store"
148177
```
149178
150-
Restart the command prompt to allow the change to take effect. Print the value of the environment variable to validate that it's set properly.
179+
If you use PowerShell, run the following command:
151180
152-
### [PowerShell](#tab/powershell)
181+
```powershell
182+
$Env:Endpoint = "endpoint-of-your-app-configuration-store"
183+
```
153184
154-
If you use Windows PowerShell, run the following command.
185+
If you use macOS or Linux, run the following command:
155186
156-
```azurepowershell
157-
$Env:ConnectionString = "connection-string-of-your-app-configuration-store"
187+
```bash
188+
export Endpoint='endpoint-of-your-app-configuration-store'
158189
```
159190
160-
### [macOS](#tab/unix)
191+
### [Connection string](#tab/connection-string)
192+
Set the environment variable named **ConnectionString** to the read-only connection string of your App Configuration store found under *Access keys* of your store in the Azure portal.
161193
162-
If you use macOS, run the following command.
194+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
163195
164-
```console
165-
export ConnectionString='connection-string-of-your-app-configuration-store'
196+
```cmd
197+
setx ConnectionString "connection-string-of-your-app-configuration-store"
166198
```
167199
168-
### [Linux](#tab/linux)
200+
If you use PowerShell, run the following command:
201+
202+
```powershell
203+
$Env:ConnectionString = "connection-string-of-your-app-configuration-store"
204+
```
169205
170-
If you use Linux, run the following command.
206+
If you use macOS or Linux, run the following command:
171207
172-
```console
208+
```bash
173209
export ConnectionString='connection-string-of-your-app-configuration-store'
174210
```
175-
176211
---
177212
178213
1. Run the following command to build the app.

0 commit comments

Comments
 (0)