Skip to content

Commit 2e66e3e

Browse files
authored
Merge pull request #294602 from maud-lv/ml-EID-quickstart-feature-flag-dotnet
Add Entra ID tab to quickstart-feature-flag-dotnet
2 parents f22504f + 07c096d commit 2e66e3e

File tree

1 file changed

+87
-17
lines changed

1 file changed

+87
-17
lines changed

articles/azure-app-configuration/quickstart-feature-flag-dotnet.md

Lines changed: 87 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,40 +46,113 @@ You can use Visual Studio to create a new console app project.
4646

4747
## Use the feature flag
4848

49-
1. Right-click your project, and select **Manage NuGet Packages**. On the **Browse** tab, search and add the following NuGet packages to your project.
49+
1. Right-click your project and select **Manage NuGet Packages**. On the **Browse** tab, search and add the latest stable versions of the following NuGet packages to your project.
50+
51+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
5052

5153
```
5254
Microsoft.Extensions.Configuration.AzureAppConfiguration
5355
Microsoft.FeatureManagement
56+
Azure.Identity
5457
```
5558
56-
Make sure that the version of `Microsoft.FeatureManagement` is greater than 3.1.0.
59+
### [Connection string](#tab/connection-string)
60+
61+
```
62+
Microsoft.Extensions.Configuration.AzureAppConfiguration
63+
Microsoft.FeatureManagement
64+
```
65+
---
5766
5867
1. Open *Program.cs* and add the following statements.
5968
69+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
70+
71+
```csharp
72+
using Microsoft.Extensions.Configuration;
73+
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
74+
using Microsoft.FeatureManagement;
75+
using Azure.Identity;
76+
```
77+
78+
### [Connection string](#tab/connection-string)
79+
6080
```csharp
6181
using Microsoft.Extensions.Configuration;
6282
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
6383
using Microsoft.FeatureManagement;
6484
```
85+
---
86+
87+
1. Update the *Program.cs* file and add a call to the `UseFeatureFlags` method to load feature flags from App Configuration. Then create a `FeatureManager` to read feature flags from the configuration. Finally, display a message if the *Beta* feature flag is enabled.
6588
66-
1. Connect to App Configuration, specifying the `UseFeatureFlags` option so that feature flags are retrieved. Create a `ConfigurationFeatureDefinitionProvider` to provide feature flag definition from the configuration and a `FeatureManager` to evaluate feature flags' state. Then display a message if the `Beta` feature flag is enabled.
89+
You can connect to your App Configuration store using Microsoft Entra ID (recommended) or a connection string.
6790
68-
### [.NET](#tab/dotnet)
91+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
92+
93+
You use the `DefaultAzureCredential` to authenticate to your App Configuration store by default. Follow the [instructions](./concept-enable-rbac.md#authentication-with-token-credentials) to assign your credential the **App Configuration Data Reader** role. Be sure to allow sufficient time for the permission to propagate before running your application.
94+
95+
#### .NET
6996
7097
```csharp
7198
IConfiguration configuration = new ConfigurationBuilder()
7299
.AddAzureAppConfiguration(options =>
73100
{
74-
options.Connect(Environment.GetEnvironmentVariable("ConnectionString"))
75-
.UseFeatureFlags();
101+
string endpoint = Environment.GetEnvironmentVariable("Endpoint");
102+
options.Connect(new Uri(endpoint), new DefaultAzureCredential());
103+
.UseFeatureFlags();
76104
}).Build();
77105
78-
IFeatureDefinitionProvider featureDefinitionProvider = new ConfigurationFeatureDefinitionProvider(configuration);
106+
var featureManager = new FeatureManager(
107+
new ConfigurationFeatureDefinitionProvider(configuration));
108+
109+
if (await featureManager.IsEnabledAsync("Beta"))
110+
{
111+
Console.WriteLine("Welcome to the beta!");
112+
}
113+
114+
Console.WriteLine("Hello World!");
115+
```
79116
80-
IVariantFeatureManager featureManager = new FeatureManager(
81-
featureDefinitionProvider,
82-
new FeatureManagementOptions());
117+
#### .NET Framework
118+
119+
```csharp
120+
public static async Task Main(string[] args)
121+
{
122+
IConfiguration configuration = new ConfigurationBuilder()
123+
.AddAzureAppConfiguration(options =>
124+
{
125+
string endpoint = Environment.GetEnvironmentVariable("Endpoint");
126+
options.Connect(new Uri(endpoint), new DefaultAzureCredential());
127+
.UseFeatureFlags();
128+
}).Build();
129+
130+
var featureManager = new FeatureManager(
131+
new ConfigurationFeatureDefinitionProvider(configuration));
132+
133+
if (await featureManager.IsEnabledAsync("Beta"))
134+
{
135+
Console.WriteLine("Welcome to the beta!");
136+
}
137+
138+
Console.WriteLine("Hello World!");
139+
}
140+
```
141+
142+
### [Connection string](#tab/connection-string)
143+
144+
#### .NET
145+
146+
```csharp
147+
IConfiguration configuration = new ConfigurationBuilder()
148+
.AddAzureAppConfiguration(options =>
149+
{
150+
options.Connect(Environment.GetEnvironmentVariable("ConnectionString"))
151+
.UseFeatureFlags();
152+
}).Build();
153+
154+
var featureManager = new FeatureManager(
155+
new ConfigurationFeatureDefinitionProvider(configuration));
83156
84157
if (await featureManager.IsEnabledAsync("Beta"))
85158
{
@@ -89,7 +162,7 @@ You can use Visual Studio to create a new console app project.
89162
Console.WriteLine("Hello World!");
90163
```
91164
92-
### [.NET Framework](#tab/dotnet-framework)
165+
#### .NET Framework
93166
94167
```csharp
95168
public static async Task Main(string[] args)
@@ -98,14 +171,11 @@ You can use Visual Studio to create a new console app project.
98171
.AddAzureAppConfiguration(options =>
99172
{
100173
options.Connect(Environment.GetEnvironmentVariable("ConnectionString"))
101-
.UseFeatureFlags();
174+
.UseFeatureFlags();
102175
}).Build();
103176
104-
IFeatureDefinitionProvider featureDefinitionProvider = new ConfigurationFeatureDefinitionProvider(configuration);
105-
106-
IVariantFeatureManager featureManager = new FeatureManager(
107-
featureDefinitionProvider,
108-
new FeatureManagementOptions());
177+
var featureManager = new FeatureManager(
178+
new ConfigurationFeatureDefinitionProvider(configuration));
109179
110180
if (await featureManager.IsEnabledAsync("Beta"))
111181
{

0 commit comments

Comments
 (0)