Skip to content

Commit 27b9b06

Browse files
authored
Merge pull request #91683 from lisaguthrie/netfxfeatures
Initial feature management quickstart for NETFX
2 parents b6e33d5 + d9a63d1 commit 27b9b06

File tree

7 files changed

+278
-1
lines changed

7 files changed

+278
-1
lines changed

articles/azure-app-configuration/TOC.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
items:
2626
- name: ASP.NET Core
2727
href: quickstart-feature-flag-aspnet-core.md
28+
- name: .NET Framework
29+
href: quickstart-feature-flag-dotnet.md
2830
- name: Java Spring
2931
href: quickstart-feature-flag-spring-boot.md
3032
- name: Tutorials
@@ -33,6 +35,8 @@
3335
href: enable-dynamic-configuration-aspnet-core.md
3436
- name: Enable dynamic configuration in a .NET Core app
3537
href: enable-dynamic-configuration-dotnet-core.md
38+
- name: Enable dynamic configuration in .NET Framework
39+
href: enable-dynamic-configuration-dotnet.md
3640
- name: Use feature flags in a .NET Core app
3741
href: use-feature-flags-dotnet-core.md
3842
- name: Use feature flags in a Spring Boot app
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
---
2+
title: Tutorial for using Azure App Configuration dynamic configuration in a .NET Framework app | Microsoft Docs
3+
description: In this tutorial, you learn how to dynamically update the configuration data for .NET Framework apps
4+
services: azure-app-configuration
5+
documentationcenter: ''
6+
author: lisaguthrie
7+
manager: maiye
8+
editor: ''
9+
10+
ms.assetid:
11+
ms.service: azure-app-configuration
12+
ms.workload: tbd
13+
ms.devlang: csharp
14+
ms.topic: tutorial
15+
ms.date: 10/21/2019
16+
ms.author: lcozzens
17+
18+
#Customer intent: I want to dynamically update my .NET Framework app to use the latest configuration data in App Configuration.
19+
---
20+
# Tutorial: Use dynamic configuration in a .NET Framework app
21+
22+
The App Configuration .NET client library supports updating a set of configuration settings on demand without causing an application to restart. This can be implemented by first getting an instance of `IConfigurationRefresher` from the options for the configuration provider and then calling `Refresh` on that instance anywhere in your code.
23+
24+
In order to keep the settings updated and avoid too many calls to the configuration store, a cache is used for each setting. Until the cached value of a setting has expired, the refresh operation does not update the value, even when the value has changed in the configuration store. The default expiration time for each request is 30 seconds, but it can be overridden if required.
25+
26+
This tutorial shows how you can implement dynamic configuration updates in your code. It builds on the app introduced in the quickstarts. Before you continue, finish [Create a .NET Framework app with App Configuration](./quickstart-dotnet-app.md) first.
27+
28+
In this tutorial, you learn how to:
29+
30+
> [!div class="checklist"]
31+
> * Set up your application to update its configuration with an app configuration store on demand.
32+
> * Inject the latest configuration in your application's controllers.
33+
34+
## Prerequisites
35+
36+
- Azure subscription - [create one for free](https://azure.microsoft.com/free/)
37+
- [Visual Studio 2019](https://visualstudio.microsoft.com/vs)
38+
- [.NET Framework 4.7.1 or later](https://dotnet.microsoft.com/download)
39+
40+
## Create an app configuration store
41+
42+
[!INCLUDE [azure-app-configuration-create](../../includes/azure-app-configuration-create.md)]
43+
44+
6. Select **Configuration Explorer** > **+ Create** to add the following key-value pairs:
45+
46+
| Key | Value |
47+
|---|---|
48+
| TestApp:Settings:Message | Data from Azure App Configuration |
49+
50+
Leave **Label** and **Content Type** empty for now.
51+
52+
## Create a .NET console app
53+
54+
1. Start Visual Studio, and select **File** > **New** > **Project**.
55+
56+
1. In **Create a new project**, filter on the **Console** project type and click on **Console App (.NET Framework)**. Click **Next**.
57+
58+
1. In **Configure your new project**, enter a project name. Under **Framework**, select **.NET Framework 4.7.1** or higher. Click **Create**.
59+
60+
## Reload data from App Configuration
61+
1. Right-click your project, and select **Manage NuGet Packages**. On the **Browse** tab, search and add the *Microsoft.Extensions.Configuration.AzureAppConfiguration* NuGet package to your project. If you can't find it, select the **Include prerelease** check box.
62+
63+
1. Open *Program.cs*, and add a reference to the .NET Core App Configuration provider.
64+
65+
```csharp
66+
using Microsoft.Extensions.Configuration;
67+
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
68+
```
69+
70+
1. Add two variables to store configuration-related objects.
71+
72+
```csharp
73+
private static IConfiguration _configuration = null;
74+
private static IConfigurationRefresher _refresher = null;
75+
```
76+
77+
1. Update the `Main` method to connect to App Configuration with the specified refresh options.
78+
79+
```csharp
80+
static void Main(string[] args)
81+
{
82+
var builder = new ConfigurationBuilder();
83+
builder.AddAzureAppConfiguration(options =>
84+
{
85+
options.Connect(Environment.GetEnvironmentVariable("ConnectionString"))
86+
.ConfigureRefresh(refresh =>
87+
{
88+
refresh.Register("TestApp:Settings:Message")
89+
.SetCacheExpiration(TimeSpan.FromSeconds(10));
90+
});
91+
92+
_refresher = options.GetRefresher();
93+
});
94+
95+
_configuration = builder.Build();
96+
PrintMessage().Wait();
97+
}
98+
```
99+
The `ConfigureRefresh` method is used to specify the settings used to update the configuration data with the app configuration store when a refresh operation is triggered. An instance of `IConfigurationRefresher` can be retrieved by calling `GetRefresher` method on the options provided to `AddAzureAppConfiguration` method, and the `Refresh` method on this instance can be used to trigger a refresh operation anywhere in your code.
100+
101+
> [!NOTE]
102+
> The default cache expiration time for a configuration setting is 30 seconds, but can be overridden by calling the `SetCacheExpiration` method on the options initializer passed as an argument to the `ConfigureRefresh` method.
103+
104+
1. Add a method called `PrintMessage()` that triggers a manual refresh of configuration data from App Configuration.
105+
106+
```csharp
107+
private static async Task PrintMessage()
108+
{
109+
Console.WriteLine(_configuration["TestApp:Settings:Message"] ?? "Hello world!");
110+
111+
// Wait for the user to press Enter
112+
Console.ReadLine();
113+
114+
await _refresher.Refresh();
115+
Console.WriteLine(_configuration["TestApp:Settings:Message"] ?? "Hello world!");
116+
}
117+
```
118+
119+
## Build and run the app locally
120+
121+
1. Set an environment variable named **ConnectionString**, and set it to the access key to your app configuration store. If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
122+
123+
setx ConnectionString "connection-string-of-your-app-configuration-store"
124+
125+
If you use Windows PowerShell, run the following command:
126+
127+
$Env:ConnectionString = "connection-string-of-your-app-configuration-store"
128+
129+
1. Restart Visual Studio to allow the change to take effect.
130+
131+
1. Press Ctrl + F5 to build and run the console app.
132+
133+
![App launch local](./media/dotnet-app-run.png)
134+
135+
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.
136+
137+
1. Select **Configuration Explorer**, and update the values of the following keys:
138+
139+
| Key | Value |
140+
|---|---|
141+
| TestApp:Settings:Message | Data from Azure App Configuration - Updated |
142+
143+
1. Back in the running application, press the Enter key to trigger a refresh and print the updated value in the Command Prompt or PowerShell window.
144+
145+
![App refresh local](./media/dotnet-app-run-refresh.png)
146+
147+
> [!NOTE]
148+
> Since the cache expiration time was set to 10 seconds using the `SetCacheExpiration` method while specifying the configuration for the refresh operation, the value for the configuration setting will only be updated if at least 10 seconds have elapsed since the last refresh for that setting.
149+
150+
## Clean up resources
151+
152+
[!INCLUDE [azure-app-configuration-cleanup](../../includes/azure-app-configuration-cleanup.md)]
153+
154+
## Next steps
155+
156+
In this tutorial, you added an Azure managed service identity to streamline access to App Configuration and improve credential management for your app. To learn how to add an Azure-managed service identity that streamlines access to App Configuration, continue to the next tutorial.
157+
158+
> [!div class="nextstepaction"]
159+
> [Managed identity integration](./howto-integrate-azure-managed-service-identity.md)

articles/azure-app-configuration/index.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ sections:
5757
values:
5858
- href: /azure/azure-app-configuration/quickstart-feature-flag-aspnet-core
5959
- href:
60-
- href:
60+
- href: /azure/azure-app-configuration/quickstart-feature-flag-dotnet
6161
- href:
6262
- href: /azure/azure-app-configuration/quickstart-feature-flag-spring-boot
6363
- title: Step-by-step tutorials
29.1 KB
Loading
19.4 KB
Loading
22.9 KB
Loading
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
---
2+
title: Quickstart for adding feature flags to .NET Framework apps | Microsoft Docs | Microsoft Docs
3+
description: A quickstart for adding feature flags to .NET Framework apps and managing them in Azure App Configuration
4+
services: azure-app-configuration
5+
documentationcenter: ''
6+
author: lisaguthrie
7+
manager: maiye
8+
editor: ''
9+
10+
ms.assetid:
11+
ms.service: azure-app-configuration
12+
ms.devlang: csharp
13+
ms.topic: quickstart
14+
ms.tgt_pltfrm: .NET
15+
ms.workload: tbd
16+
ms.date: 10/21/2019
17+
ms.author: lcozzens
18+
19+
#Customer intent: As a .NET Framework developer, I want to use feature flags to control feature availability quickly and confidently.
20+
---
21+
# Quickstart: Add feature flags to a .NET Framework app
22+
23+
In this quickstart, you incorporate Azure App Configuration into a .NET Framework 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.
24+
25+
The .NET Feature Management libraries extend the framework with comprehensive feature flag support. These libraries are built on top of the .NET configuration system. They seamlessly integrate with App Configuration through its .NET configuration provider.
26+
27+
## Prerequisites
28+
29+
- Azure subscription - [create one for free](https://azure.microsoft.com/free/)
30+
- [Visual Studio 2019](https://visualstudio.microsoft.com/vs)
31+
- [.NET Framework 4.7.2](https://dotnet.microsoft.com/download)
32+
33+
## Create an app configuration store
34+
35+
[!INCLUDE [azure-app-configuration-create](../../includes/azure-app-configuration-create.md)]
36+
37+
## Create a .NET console app
38+
39+
1. Start Visual Studio, and select **File** > **New** > **Project**.
40+
41+
1. In **Create a new project**, filter on the **Console** project type and click on **Console App (.NET Framework)**. Click **Next**.
42+
43+
1. In **Configure your new project**, enter a project name. Under **Framework**, select **.NET Framework 4.7.1** or higher. Click **Create**.
44+
45+
## Connect to an app configuration store
46+
47+
1. Right-click your project, and select **Manage NuGet Packages**. On the **Browse** tab, search and add the following NuGet packages to your project. If you can't find them, select the **Include prerelease** check box.
48+
49+
```
50+
Microsoft.Extensions.DependencyInjection
51+
Microsoft.Extensions.Configuration.AzureAppConfiguration
52+
Microsoft.FeatureManagement
53+
```
54+
55+
1. Open *Program.cs* and add the following statements:
56+
57+
```csharp
58+
using Microsoft.Extensions.DependencyInjection;
59+
using Microsoft.Extensions.Configuration;
60+
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
61+
using Microsoft.FeatureManagement;
62+
```
63+
64+
1. Update the `Main` method to connect to App Configuration, specifying the `UseFeatureFlags` option so that feature flags are retrieved. Then display a message if the `Beta` feature flag is enabled.
65+
66+
```csharp
67+
static void Main(string[] args)
68+
{
69+
IConfigurationRoot configuration = new ConfigurationBuilder()
70+
.AddAzureAppConfiguration(options =>
71+
{
72+
options.Connect(Environment.GetEnvironmentVariable("ConnectionString"))
73+
.UseFeatureFlags();
74+
}).Build();
75+
76+
IServiceCollection services = new ServiceCollection();
77+
services.AddSingleton<IConfiguration>(configuration).AddFeatureManagement();
78+
IFeatureManager featureManager = services.BuildServiceProvider().GetRequiredService<IFeatureManager>();
79+
80+
if (featureManager.IsEnabled("Beta"))
81+
{
82+
Console.WriteLine("Welcome to the beta");
83+
}
84+
85+
Console.WriteLine("Hello World!");
86+
}
87+
```
88+
89+
## Build and run the app locally
90+
91+
1. Set an environment variable named **ConnectionString** to the connection string of your app configuration store. If you use the Windows command prompt, run the following command:
92+
93+
setx ConnectionString "connection-string-of-your-app-configuration-store"
94+
95+
If you use Windows PowerShell, run the following command:
96+
97+
$Env:ConnectionString = "connection-string-of-your-app-configuration-store"
98+
99+
1. Restart Visual Studio to allow the change to take effect.
100+
101+
1. Press Ctrl + F5 to build and run the console app.
102+
103+
![App with feature flag enabled](./media/quickstarts/dotnet-app-feature-flag.png)
104+
105+
## Clean up resources
106+
107+
[!INCLUDE [azure-app-configuration-cleanup](../../includes/azure-app-configuration-cleanup.md)]
108+
109+
## Next steps
110+
111+
In this quickstart, you created a feature flag in App Configuration and used it with a .NET Framework console app. To learn how to dynamically update feature flags and other configuration values without restarting the application, continue to the next tutorial.
112+
113+
> [!div class="nextstepaction"]
114+
> [Enable dynamic configuration](./enable-dynamic-configuration-dotnet.md)

0 commit comments

Comments
 (0)