Skip to content

Commit 9cb9152

Browse files
maud-lvcmaneu
andcommitted
Add using statements
Co-Authored-By: Christopher Maneu <[email protected]>
1 parent 1dd7ce9 commit 9cb9152

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

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

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ services: azure-app-configuration
55
author: zhenlan
66
ms.service: azure-app-configuration
77
ms.devlang: csharp
8-
ms.custom: devx-track-csharp, contperf-fy21q1, mode-other
8+
ms.custom: devx-track-csharp, contperf-fy21q1, mode-other, engagement-fy23
99
ms.topic: quickstart
10-
ms.date: 9/29/2022
10+
ms.date: 12/16/2022
1111
ms.author: zhenlwa
1212
#Customer intent: As an ASP.NET Core developer, I want to learn how to manage all my app settings in one place.
1313
---
@@ -45,14 +45,17 @@ Use the [.NET Core command-line interface (CLI)](/dotnet/core/tools) to create a
4545
Run the following command to create an ASP.NET Core web app in a new *TestAppConfig* folder:
4646

4747
#### [.NET 6.x](#tab/core6x)
48+
4849
```dotnetcli
4950
dotnet new webapp --output TestAppConfig --framework net6.0
5051
```
5152

5253
#### [.NET Core 3.x](#tab/core3x)
54+
5355
```dotnetcli
5456
dotnet new webapp --output TestAppConfig --framework netcoreapp3.1
5557
```
58+
5659
---
5760

5861
## Connect to the App Configuration store
@@ -75,10 +78,16 @@ dotnet new webapp --output TestAppConfig --framework netcoreapp3.1
7578
7679
Secret Manager stores the secret outside of your project tree, which helps prevent the accidental sharing of secrets within source code. It's used only to test the web app locally. When the app is deployed to Azure like [App Service](../app-service/overview.md), use the *Connection strings*, *Application settings* or environment variables to store the connection string. Alternatively, to avoid connection strings all together, you can [connect to App Configuration using managed identities](./howto-integrate-azure-managed-service-identity.md) or your other [Azure AD identities](./concept-enable-rbac.md).
7780
78-
1. Open *Program.cs*, and add Azure App Configuration as an extra configuration source by calling the `AddAzureAppConfiguration` method.
81+
1. Open *Program.cs*, add the `using TestAppConfig;` statement and add Azure App Configuration as an extra configuration source by calling the `AddAzureAppConfiguration` method.
7982
8083
#### [.NET 6.x](#tab/core6x)
84+
8185
```csharp
86+
// Existing code in Program.cs
87+
// ... ...
88+
89+
using TestAppConfig;
90+
8291
var builder = WebApplication.CreateBuilder(args);
8392
8493
// Retrieve the connection string
@@ -90,10 +99,11 @@ dotnet new webapp --output TestAppConfig --framework netcoreapp3.1
9099
// The rest of existing code in program.cs
91100
// ... ...
92101
```
93-
102+
94103
#### [.NET Core 3.x](#tab/core3x)
104+
95105
Update the `CreateHostBuilder` method.
96-
106+
97107
```csharp
98108
public static IHostBuilder CreateHostBuilder(string[] args) =>
99109
Host.CreateDefaultBuilder(args)
@@ -112,6 +122,7 @@ dotnet new webapp --output TestAppConfig --framework netcoreapp3.1
112122
webBuilder.UseStartup<Startup>();
113123
});
114124
```
125+
115126
---
116127
117128
This code will connect to your App Configuration store using a connection string and load *all* key-values that have *no labels*. For more information on the App Configuration provider, see the [App Configuration provider API reference](/dotnet/api/Microsoft.Extensions.Configuration.AzureAppConfiguration).
@@ -120,7 +131,7 @@ dotnet new webapp --output TestAppConfig --framework netcoreapp3.1
120131
121132
In this example, you'll update a web page to display its content using the settings you configured in your App Configuration store.
122133
123-
1. Add a *Settings.cs* file at the root of your project directory. It defines a strongly typed `Settings` class for the configuration you're going to use. Replace the namespace with the name of your project.
134+
1. Add a *Settings.cs* file at the root of your project directory. It defines a strongly typed `Settings` class for the configuration you're going to use. Replace the namespace with the name of your project.
124135
125136
```csharp
126137
namespace TestAppConfig
@@ -138,6 +149,7 @@ In this example, you'll update a web page to display its content using the setti
138149
1. Bind the `TestApp:Settings` section in configuration to the `Settings` object.
139150
140151
#### [.NET 6.x](#tab/core6x)
152+
141153
Update *Program.cs* with the following code.
142154
143155
```csharp
@@ -154,10 +166,11 @@ In this example, you'll update a web page to display its content using the setti
154166
// The rest of existing code in program.cs
155167
// ... ...
156168
```
157-
169+
158170
#### [.NET Core 3.x](#tab/core3x)
171+
159172
Open *Startup.cs* and update the `ConfigureServices` method.
160-
173+
161174
```csharp
162175
public void ConfigureServices(IServiceCollection services)
163176
{
@@ -167,11 +180,17 @@ In this example, you'll update a web page to display its content using the setti
167180
services.Configure<Settings>(Configuration.GetSection("TestApp:Settings"));
168181
}
169182
```
183+
170184
---
171185
172-
1. Open *Index.cshtml.cs* in the *Pages* directory, and update the `IndexModel` class with the following code. Add `using Microsoft.Extensions.Options` namespace at the beginning of the file, if it's not already there.
186+
1. Open *Index.cshtml.cs* in the *Pages* directory. Add the [Microsoft.Extensions.Options](/dotnet/api/microsoft.extensions.options) namespace and update the `IndexModel` class with the following code.
173187
174188
```csharp
189+
// Existing code in Index.cshtml.cs
190+
// ... ...
191+
192+
using Microsoft.Extensions.Options;
193+
175194
public class IndexModel : PageModel
176195
{
177196
private readonly ILogger<IndexModel> _logger;
@@ -223,7 +242,7 @@ In this example, you'll update a web page to display its content using the setti
223242
dotnet run
224243
```
225244
226-
1. Open a browser and navigate to the URL the app is listening on, as specified in the command output. It looks like `https://localhost:5001`.
245+
1. Open a browser and navigate to the URL the app is listening on, as specified in the command output. It looks like `https://localhost:5001`.
227246
228247
If you're working in the Azure Cloud Shell, select the *Web Preview* button followed by *Configure*. When prompted to configure the port for preview, enter *5000*, and select *Open and browse*.
229248
@@ -248,4 +267,4 @@ In this quickstart, you:
248267
To learn how to configure your ASP.NET Core web app to dynamically refresh configuration settings, continue to the next tutorial.
249268
250269
> [!div class="nextstepaction"]
251-
> [Enable dynamic configuration](./enable-dynamic-configuration-aspnet-core.md)
270+
> [Enable dynamic configuration](./enable-dynamic-configuration-aspnet-core.md)

0 commit comments

Comments
 (0)