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
#Customer intent: As an ASP.NET Core developer, I want to learn how to manage all my app settings in one place.
13
13
---
@@ -71,122 +71,125 @@ dotnet new mvc --no-https --output TestAppConfig
71
71
72
72
Access this secret using the .NET Core Configuration API. A colon (`:`) works in the configuration name with the Configuration API on all supported platforms. For more information, see [Configuration keys and values](/aspnet/core/fundamentals/configuration#configuration-keys-and-values).
73
73
74
-
> [!IMPORTANT]
75
-
> `CreateHostBuilder` replaces `CreateWebHostBuilder` in .NET Core 3.x. Select the correct syntax based on your environment.
74
+
1. Select the correct syntax based on your environment.
76
75
77
-
#### [.NET 6.x](#tab/core6x)
76
+
#### [.NET 6.x](#tab/core6x)
77
+
In *Program.cs*, and replace its content with the following code:
78
78
79
-
1. In *Program.cs*, and replace its content with the following code:
80
-
```csharp
81
-
var builder = WebApplication.CreateBuilder(args);
82
-
builder.Host.ConfigureAppConfiguration(builder =>
83
-
{
84
-
builder.AddAzureAppConfiguration(options =>
85
-
{
86
-
//Connect to your App Config Store using a connection string
This code will connect to your App Configuration Store using a connection string and load all keys that have the *TestApp* prefix from a previous step.
121
+
122
+
123
+
#### [.NET 5.x](#tab/core5x)
124
+
125
+
1. In *Program.cs*, add a reference to the .NET Core Configuration API namespace:
126
+
127
+
```csharp
128
+
using Microsoft.Extensions.Configuration;
129
+
```
130
+
131
+
> [!IMPORTANT]
132
+
> `CreateHostBuilder` in .NET 5.x replaces `CreateWebHostBuilder` in .NET Core 3.x.
133
+
134
+
1. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `AddAzureAppConfiguration` method.
135
+
136
+
```csharp
137
+
public static IHostBuilder CreateHostBuilder(string[] args) =>
138
+
Host.CreateDefaultBuilder(args)
139
+
.ConfigureWebHostDefaults(webBuilder =>
140
+
webBuilder.ConfigureAppConfiguration(config =>
93
141
{
94
-
// Make Azure App Configuration services available through dependency injection
95
-
services.AddAzureAppConfiguration()
96
-
.AddControllersWithViews();
97
-
});
142
+
var settings = config.Build();
143
+
var connection = settings.GetConnectionString("AppConfig");
144
+
config.AddAzureAppConfiguration(connection);
145
+
}).UseStartup<Startup>());
146
+
```
147
+
#### [.NET Core 3.x](#tab/core3x)
148
+
1. In *Program.cs*, add a reference to the .NET Core Configuration API namespace:
98
149
99
-
var app = builder.Build();
150
+
```csharp
151
+
using Microsoft.Extensions.Configuration;
152
+
```
100
153
101
-
// Configure the HTTP request pipeline.
102
-
if (!app.Environment.IsDevelopment())
103
-
{
104
-
app.UseExceptionHandler("/Home/Error");
105
-
}
106
-
app.UseStaticFiles();
154
+
1. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `AddAzureAppConfiguration` method.
107
155
108
-
app.UseAzureAppConfiguration();
156
+
```csharp
157
+
public static IHostBuilder CreateHostBuilder(string[] args) =>
158
+
Host.CreateDefaultBuilder(args)
159
+
.ConfigureWebHostDefaults(webBuilder =>
160
+
webBuilder.ConfigureAppConfiguration(config =>
161
+
{
162
+
var settings = config.Build();
163
+
var connection = settings.GetConnectionString("AppConfig");
164
+
config.AddAzureAppConfiguration(connection);
165
+
}).UseStartup<Startup>());
166
+
```
109
167
110
-
app.UseRouting();
168
+
#### [.NET Core 2.x](#tab/core2x)
111
169
112
-
app.UseAuthorization();
170
+
1. In *Program.cs*, add a reference to the .NET Core Configuration API namespace:
This will connect to your App Configuration Store using a connection string and load all keys that have the *TestApp* prefix from a previous step.
121
-
122
-
123
-
#### [.NET 5.x](#tab/core5x)
124
-
125
-
1. In *Program.cs*, add a reference to the .NET Core Configuration API namespace:
126
-
127
-
```csharp
128
-
using Microsoft.Extensions.Configuration;
129
-
```
130
-
131
-
1. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `AddAzureAppConfiguration` method.
132
-
133
-
```csharp
134
-
public static IHostBuilder CreateHostBuilder(string[] args) =>
135
-
Host.CreateDefaultBuilder(args)
136
-
.ConfigureWebHostDefaults(webBuilder =>
137
-
webBuilder.ConfigureAppConfiguration(config =>
138
-
{
139
-
var settings = config.Build();
140
-
var connection = settings.GetConnectionString("AppConfig");
141
-
config.AddAzureAppConfiguration(connection);
142
-
}).UseStartup<Startup>());
143
-
```
144
-
#### [.NET Core 3.x](#tab/core3x)
145
-
1. In *Program.cs*, add a reference to the .NET Core Configuration API namespace:
146
-
147
-
```csharp
148
-
using Microsoft.Extensions.Configuration;
149
-
```
150
-
151
-
1. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `AddAzureAppConfiguration` method.
152
-
153
-
```csharp
154
-
public static IHostBuilder CreateHostBuilder(string[] args) =>
155
-
Host.CreateDefaultBuilder(args)
156
-
.ConfigureWebHostDefaults(webBuilder =>
157
-
webBuilder.ConfigureAppConfiguration(config =>
176
+
1. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `AddAzureAppConfiguration` method.
177
+
178
+
```csharp
179
+
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
180
+
WebHost.CreateDefaultBuilder(args)
181
+
.ConfigureAppConfiguration(config =>
158
182
{
159
183
var settings = config.Build();
160
184
var connection = settings.GetConnectionString("AppConfig");
161
185
config.AddAzureAppConfiguration(connection);
162
-
}).UseStartup<Startup>());
163
-
```
164
-
165
-
#### [.NET Core 2.x](#tab/core2x)
166
-
167
-
1. In *Program.cs*, add a reference to the .NET Core Configuration API namespace:
168
-
169
-
```csharp
170
-
using Microsoft.Extensions.Configuration;
171
-
```
172
-
173
-
1. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `AddAzureAppConfiguration` method.
174
-
175
-
```csharp
176
-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
177
-
WebHost.CreateDefaultBuilder(args)
178
-
.ConfigureAppConfiguration(config =>
179
-
{
180
-
var settings = config.Build();
181
-
var connection = settings.GetConnectionString("AppConfig");
182
-
config.AddAzureAppConfiguration(connection);
183
-
})
184
-
.UseStartup<Startup>();
185
-
```
186
-
187
-
---
186
+
})
187
+
.UseStartup<Startup>();
188
+
```
189
+
190
+
---
188
191
189
-
With the preceding change, the [configuration provider for App Configuration](/dotnet/api/Microsoft.Extensions.Configuration.AzureAppConfiguration) has been registered with the .NET Core Configuration API.
192
+
With the preceding change, the [configuration provider for App Configuration](/dotnet/api/Microsoft.Extensions.Configuration.AzureAppConfiguration) has been registered with the .NET Core Configuration API.
0 commit comments