Skip to content

Commit 953c845

Browse files
Fix formatting and indentation
1 parent 526766f commit 953c845

File tree

1 file changed

+105
-102
lines changed

1 file changed

+105
-102
lines changed

articles/azure-app-configuration/quickstart-aspnet-core-app.md

Lines changed: 105 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.service: azure-app-configuration
77
ms.devlang: csharp
88
ms.custom: devx-track-csharp, contperf-fy21q1, mode-other
99
ms.topic: quickstart
10-
ms.date: 09/25/2020
10+
ms.date: 1/3/2022
1111
ms.author: alkemper
1212
#Customer intent: As an ASP.NET Core developer, I want to learn how to manage all my app settings in one place.
1313
---
@@ -71,122 +71,125 @@ dotnet new mvc --no-https --output TestAppConfig
7171
7272
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).
7373
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.
7675
77-
#### [.NET 6.x](#tab/core6x)
76+
#### [.NET 6.x](#tab/core6x)
77+
In *Program.cs*, and replace its content with the following code:
7878
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
87-
options.Connect(Environment.GetEnvironmentVariable("AppConfig"))
88-
// Load all keys that start with `TestApp:` and have no label
89-
.Select("TestApp:*");
90-
});
91-
})
92-
.ConfigureServices(services =>
79+
```csharp
80+
var builder = WebApplication.CreateBuilder(args);
81+
builder.Host.ConfigureAppConfiguration(builder =>
82+
{
83+
builder.AddAzureAppConfiguration(options =>
84+
{
85+
//Connect to your App Config Store using a connection string
86+
options.Connect(Environment.GetEnvironmentVariable("AppConfig"))
87+
// Load all keys that start with `TestApp:` and have no label
88+
.Select("TestApp:*");
89+
});
90+
})
91+
.ConfigureServices(services =>
92+
{
93+
// Make Azure App Configuration services available through dependency injection
94+
services.AddAzureAppConfiguration()
95+
.AddControllersWithViews();
96+
});
97+
98+
var app = builder.Build();
99+
100+
// Configure the HTTP request pipeline.
101+
if (!app.Environment.IsDevelopment())
102+
{
103+
app.UseExceptionHandler("/Home/Error");
104+
}
105+
app.UseStaticFiles();
106+
107+
app.UseAzureAppConfiguration();
108+
109+
app.UseRouting();
110+
111+
app.UseAuthorization();
112+
113+
app.MapControllerRoute(
114+
name: "default",
115+
pattern: "{controller=Home}/{action=Index}/{id?}");
116+
117+
app.Run();
118+
```
119+
120+
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 =>
93141
{
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:
98149
99-
var app = builder.Build();
150+
```csharp
151+
using Microsoft.Extensions.Configuration;
152+
```
100153
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.
107155
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+
```
109167
110-
app.UseRouting();
168+
#### [.NET Core 2.x](#tab/core2x)
111169
112-
app.UseAuthorization();
170+
1. In *Program.cs*, add a reference to the .NET Core Configuration API namespace:
113171
114-
app.MapControllerRoute(
115-
name: "default",
116-
pattern: "{controller=Home}/{action=Index}/{id?}");
172+
```csharp
173+
using Microsoft.Extensions.Configuration;
174+
```
117175
118-
app.Run();
119-
```
120-
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 =>
158182
{
159183
var settings = config.Build();
160184
var connection = settings.GetConnectionString("AppConfig");
161185
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+
---
188191
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.
190193
191194
## Read from the App Configuration store
192195

0 commit comments

Comments
 (0)