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/quickstart-feature-flag-aspnet-core.md
+97-38Lines changed: 97 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,27 +1,19 @@
1
1
---
2
-
title: Quickstart for adding feature flags to ASP.NET Core | Microsoft Docs
3
-
description: A quickstart for adding feature flags to ASP.NET Core apps and managing them in Azure App Configuration
4
-
services: azure-app-configuration
5
-
documentationcenter: ''
6
-
author: yegu-ms
7
-
manager: maiye
8
-
editor: ''
9
-
10
-
ms.assetid:
2
+
title: Quickstart for adding feature flags to ASP.NET Core
3
+
description: Add feature flags to ASP.NET Core apps and manage them using Azure App Configuration
4
+
author: jpconnock
5
+
11
6
ms.service: azure-app-configuration
12
-
ms.devlang: csharp
13
7
ms.topic: quickstart
14
-
ms.tgt_pltfrm: ASP.NET Core
15
-
ms.workload: tbd
16
-
ms.date: 04/19/2019
17
-
ms.author: yegu
8
+
ms.date: 01/14/2020
9
+
ms.author: jeconnoc
18
10
19
11
#Customer intent: As an ASP.NET Core developer, I want to use feature flags to control feature availability quickly and confidently.
20
12
---
21
13
22
14
# Quickstart: Add feature flags to an ASP.NET Core app
23
15
24
-
In this quickstart, you incorporate Azure App Configuration into an ASP.NET Core web app to create an end-to-end implementation of feature management. You can use the App Configuration service to centrally store all your feature flags and control their states.
16
+
In this quickstart, you create an end-to-end implementation of feature management in an ASP.NET Core application using Azure App Configuration. You will use the App Configuration service to centrally store all your feature flags and control their states.
25
17
26
18
The .NET Core Feature Management libraries extend the framework with comprehensive feature flag support. These libraries are built on top of the .NET Core configuration system. They seamlessly integrate with App Configuration through its .NET Core configuration provider.
27
19
@@ -34,15 +26,16 @@ The .NET Core Feature Management libraries extend the framework with comprehensi
6. Select **Feature Manager** > **+Add** to add the following feature flags:
29
+
6. Select **Feature Manager** > **+Add** to add a feature flag called `Beta`.
30
+
31
+
> [!div class="mx-imgBorder"]
32
+
> 
38
33
39
-
| Key | State |
40
-
|---|---|
41
-
| Beta | Off |
34
+
Leave `label` undefined for now.
42
35
43
36
## Create an ASP.NET Core web app
44
37
45
-
You use the [.NET Core command-line interface (CLI)](https://docs.microsoft.com/dotnet/core/tools/) to create a new ASP.NET Core MVC web app project. The advantage of using the .NET Core CLI instead of Visual Studio is that the .NET Core CLI is available across the Windows, macOS, and Linux platforms.
38
+
Use the [.NET Core command-line interface (CLI)](https://docs.microsoft.com/dotnet/core/tools/) to create a new ASP.NET Core MVC web app project. The advantage of using the .NET Core CLI instead of Visual Studio is that the .NET Core CLI is available across the Windows, macOS, and Linux platforms.
46
39
47
40
1. Create a new folder for your project. For this quickstart, name it *TestFeatureFlags*.
48
41
@@ -56,9 +49,13 @@ You use the [.NET Core command-line interface (CLI)](https://docs.microsoft.com/
56
49
57
50
Add the [Secret Manager tool](https://docs.microsoft.com/aspnet/core/security/app-secrets) to your project. The Secret Manager tool stores sensitive data for development work outside your project tree. This approach helps prevent the accidental sharing of app secrets within source code.
58
51
52
+
> [!IMPORTANT]
53
+
> Significant differences exist between .NET Core 2.x and 3.x. Select the correct syntax based on your environment.
54
+
59
55
1. Open the *.csproj* file.
60
56
1. Add a `UserSecretsId` element as shown in the following example, and replace its value with your own, which typically is a GUID:
61
57
58
+
#### [.NET Core 2.x](#tab/core2x)
62
59
```xml
63
60
<ProjectSdk="Microsoft.NET.Sdk.Web">
64
61
@@ -74,15 +71,24 @@ Add the [Secret Manager tool](https://docs.microsoft.com/aspnet/core/security/ap
1. Add reference to the `Microsoft.Azure.AppConfiguration.AspNetCore` and the `Microsoft.FeatureManagement.AspNetCore` NuGet packages by running the following commands:
@@ -111,8 +117,8 @@ Add the [Secret Manager tool](https://docs.microsoft.com/aspnet/core/security/ap
111
117
> [!IMPORTANT]
112
118
> `CreateHostBuilder` replaces `CreateWebHostBuilder` in .NET Core 3.0. Select the correct syntax based on your environment.
113
119
114
-
### Update `CreateWebHostBuilder` for .NET Core 2.x
115
-
120
+
#### [.NET Core 2.x](#tab/core2x)
121
+
116
122
```csharp
117
123
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
118
124
WebHost.CreateDefaultBuilder(args)
@@ -127,8 +133,8 @@ Add the [Secret Manager tool](https://docs.microsoft.com/aspnet/core/security/ap
127
133
.UseStartup<Startup>();
128
134
```
129
135
130
-
### Update `CreateHostBuilder` for .NET Core 3.x
131
-
136
+
#### [.NET Core 3.x](#tab/core3x)
137
+
132
138
```csharp
133
139
public static IHostBuilder CreateHostBuilder(string[] args) =>
134
140
Host.CreateDefaultBuilder(args)
@@ -143,7 +149,7 @@ Add the [Secret Manager tool](https://docs.microsoft.com/aspnet/core/security/ap
143
149
})
144
150
.UseStartup<Startup>());
145
151
```
146
-
152
+
---
147
153
148
154
1. Open *Startup.cs*, and add references to the .NET Core feature manager:
149
155
@@ -153,22 +159,75 @@ Add the [Secret Manager tool](https://docs.microsoft.com/aspnet/core/security/ap
153
159
154
160
1. Update the `ConfigureServices` method to add feature flag support by calling the `services.AddFeatureManagement()` method. Optionally, you can include any filter to be used with feature flags by calling `services.AddFeatureFilter<FilterType>()`:
155
161
162
+
#### [.NET Core 2.x](#tab/core2x)
156
163
```csharp
157
164
public void ConfigureServices(IServiceCollection services)
public void ConfigureServices(IServiceCollection services)
173
+
{
174
+
services.AddControllersWithViews();
159
175
services.AddFeatureManagement();
160
176
}
161
177
```
178
+
---
162
179
163
180
1. Update the `Configure` method to add a middleware to allow the feature flag values to be refreshed at a recurring interval while the ASP.NET Core web app continues to receive requests.
164
-
181
+
182
+
#### [.NET Core 2.x](#tab/core2x)
183
+
```csharp
184
+
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
1. Sign in to the [Azure portal](https://portal.azure.com). Select **All resources**, and select the App Configuration store instance that you created in the quickstart.
278
341
279
-
1. Select **Feature Manager**, and change the state of the **Beta** key to **On**:
280
-
281
-
| Key | State |
282
-
|---|---|
283
-
| Beta | On |
342
+
1. Select **Feature Manager**, and change the state of the **Beta** key to **On**.
284
343
285
-
1. Restart your application by switching back to your command prompt and pressing `Ctrl-C` to cancel the running `dotnet` process, then rerunning `dotnet run`.
344
+
1. Return to the command prompt and cancel the running `dotnet` process by pressing `Ctrl-C`. Restart your application using `dotnet run`.
286
345
287
346
1. Refresh the browser page to see the new configuration settings.
0 commit comments