Skip to content

Commit cd95836

Browse files
update
1 parent edca190 commit cd95836

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

articles/azure-app-configuration/howto-targetingfilter-aspnet-core.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Targeting is a feature management strategy that enables developers to progressiv
1616

1717
- The users can be actual user accounts, but they can also be machines, devices, or any uniquely identifiable entities to which you want to roll out a feature.
1818

19-
- The groups are up to your application to define. They can be Microsoft Entra groups, your workloads at different locations, or any common attributes based on which you want to categorize your audience.
19+
- The groups are up to your application to define. For example, when targeting user accounts, you can use Microsoft Entra groups or groups denoting user locations. When targeting machines, you can group them based on rollout stages. Groups can be any common attributes based on which you want to categorize your audience.
2020

2121
In this article, you learn how to roll out a new feature in an ASP.NET Core web application to specified users and groups, using `TargetingFilter` with Azure App Configuration.
2222

@@ -49,12 +49,14 @@ In this section, you will create a web application that allows users to sign in
4949
dotnet user-secrets set ConnectionStrings:AppConfig "<your_connection_string>"
5050
```
5151
52-
1. Update the *Program.cs* with the following code.
52+
1. Update *Program.cs* with the following code.
5353
5454
``` C#
5555
// Existing code in Program.cs
5656
// ... ...
5757
58+
var builder = WebApplication.CreateBuilder(args);
59+
5860
// Retrieve the connection string
5961
string connectionString = builder.Configuration.GetConnectionString("AppConfig");
6062
@@ -65,18 +67,11 @@ In this section, you will create a web application that allows users to sign in
6567
options.UseFeatureFlags();
6668
});
6769
68-
// The rest of existing code in program.cs
69-
// ... ...
70-
```
71-
72-
``` C#
73-
// Existing code in Program.cs
74-
// ... ...
75-
7670
// Add Azure App Configuration middleware to the container of services.
7771
builder.Services.AddAzureAppConfiguration();
72+
7873
// Add feature management to the container of services.
79-
builder.Services.AddFeatureManagement()
74+
builder.Services.AddFeatureManagement();
8075
8176
// The rest of existing code in program.cs
8277
// ... ...
@@ -85,6 +80,8 @@ In this section, you will create a web application that allows users to sign in
8580
``` C#
8681
// Existing code in Program.cs
8782
// ... ...
83+
84+
var app = builder.Build();
8885
8986
// Use Azure App Configuration middleware for dynamic configuration refresh.
9087
app.UseAzureAppConfiguration();
@@ -103,7 +100,7 @@ In this section, you will create a web application that allows users to sign in
103100
<h1>This is the beta website.</h1>
104101
```
105102
106-
1. Open the *HomeController.cs* under the *Controllers* directory and update it with the following code.
103+
1. Open *HomeController.cs* under the *Controllers* directory and update it with the following code.
107104
108105
``` C#
109106
public IActionResult Beta()
@@ -153,7 +150,7 @@ At this point, you can use the feature flag to enable or disable the `Beta` feat
153150
dotnet add package Microsoft.FeatureManagement.AspNetCore
154151
```
155152

156-
1. Add a *TestTargetingContextAccessor.cs* file.
153+
1. Add *ExampleTargetingContextAccessor.cs* file.
157154

158155
```csharp
159156
using Microsoft.AspNetCore.Http;
@@ -164,12 +161,12 @@ At this point, you can use the feature flag to enable or disable the `Beta` feat
164161

165162
namespace TestFeatureFlags
166163
{
167-
public class TestTargetingContextAccessor : ITargetingContextAccessor
164+
public class ExampleTargetingContextAccessor : ITargetingContextAccessor
168165
{
169-
private const string TargetingContextLookup = "TestTargetingContextAccessor.TargetingContext";
166+
private const string TargetingContextLookup = "ExampleTargetingContextAccessor.TargetingContext";
170167
private readonly IHttpContextAccessor _httpContextAccessor;
171168

172-
public TestTargetingContextAccessor(IHttpContextAccessor httpContextAccessor)
169+
public ExampleTargetingContextAccessor(IHttpContextAccessor httpContextAccessor)
173170
{
174171
_httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
175172
}
@@ -198,11 +195,18 @@ At this point, you can use the feature flag to enable or disable the `Beta` feat
198195
}
199196
```
200197

201-
1. Add `TestTargetingContextAccessor` created in the earlier step and `TargetingFilter` to the service collection by calling the `WithTargeting` method. The `TargetingFilter` will use the `TestTargetingContextAccessor` to determine the targeting context every time that the feature flag is evaluated.
198+
1. Open `Program.cs` and add the `ExampleTargetingContextAccessor` created in the earlier step and `TargetingFilter` to the service collection by calling the `WithTargeting` method after the existing line of `AddFeatureManagement`. The `TargetingFilter` will use the `ExampleTargetingContextAccessor` to determine the targeting context every time that the feature flag is evaluated.
202199

203200
```csharp
204-
services.AddFeatureManagement()
205-
.WithTargeting<TestTargetingContextAccessor>();
201+
// Existing code in Program.cs
202+
// ... ...
203+
204+
// Add feature management to the container of services.
205+
builder.Services.AddFeatureManagement()
206+
.WithTargeting<ExampleTargetingContextAccessor>();
207+
208+
// The rest of existing code in program.cs
209+
// ... ...
206210
```
207211

208212
> [!NOTE]

0 commit comments

Comments
 (0)