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/howto-targetingfilter-aspnet-core.md
+14-60Lines changed: 14 additions & 60 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -199,68 +199,26 @@ In this section, you create a web application that allows users to sign in and u
199
199
200
200
## Enable targeting for the web application
201
201
202
-
The targeting filter evaluates a user's feature state based on the user's targeting context, which comprises the user ID and the groups the user belongs to. In this example, you use the signed-in user's email address as the user ID and the domain name of the email address as the group.
202
+
A targeting context is required for feature evaluation with targeting. You can provide it as a parameter to the `featureManager.IsEnabledAsync` API explicitly. In ASP.NET Core, the targeting context can also be provided through the service collection as an ambient context by implementing the [ITargetingContextAccessor](./feature-management-dotnet-reference.md#itargetingcontextaccessor) interface.
203
203
204
-
1. Add an *ExampleTargetingContextAccessor.cs* file with the following code. You implement the `ITargetingContextAccessor` interface to provide the targeting context for the signed-in user of the current request.
204
+
### Targeting Context Accessor
205
205
206
-
```csharp
207
-
using Microsoft.FeatureManagement.FeatureFilters;
206
+
To provide the targeting context, pass your implementation type of the `ITargetingContextAccessor` to the `WithTargeting<T>` method. If no type is provided, a default implementation is used, as shown in the following code snippet. The default targeting context accessor utilizes `HttpContext.User.Identity.Name` as `UserId` and `HttpContext.User.Claims` of type [`Role`](/dotnet/api/system.security.claims.claimtypes.role#system-security-claims-claimtypes-role) for `Groups`. You can reference the [DefaultHttpTargetingContextAccessor](https://github.com/microsoft/FeatureManagement-Dotnet/blob/main/src/Microsoft.FeatureManagement.AspNetCore/DefaultHttpTargetingContextAccessor.cs) to implement your own if customization is needed. To learn more about implementing the `ITargetingContextAccessor`, see the [feature reference for targeting](./feature-management-dotnet-reference.md#itargetingcontextaccessor).
208
207
209
-
namespace TestFeatureFlags
210
-
{
211
-
public class ExampleTargetingContextAccessor : ITargetingContextAccessor
return new ValueTask<TargetingContext>(targetingContext);
240
-
}
241
-
}
242
-
}
243
-
```
208
+
``` C#
209
+
// Existing code in Program.cs
210
+
// ... ...
244
211
245
-
1. Open the *Program.cs* file and enable the targeting filter by calling the `WithTargeting` method. You pass in the type `ExampleTargetingContextAccessor` that the targeting filter will use to get the targeting context during feature flag evaluation. Add `HttpContextAccessor` to the service collection to allow `ExampleTargetingContextAccessor` to access the signed-in user information from the `HttpContext`.
212
+
// Add feature management to the container of services
213
+
builder.Services.AddFeatureManagement()
214
+
.WithTargeting();
246
215
247
-
```csharp
248
-
// Existing code in Program.cs
249
-
// ... ...
250
-
251
-
// Add feature management to the container of services
// Add HttpContextAccessor to the container of services.
256
-
builder.Services.AddHttpContextAccessor();
257
-
258
-
// The rest of existing code in Program.cs
259
-
// ... ...
260
-
```
261
-
262
-
> [!NOTE]
263
-
> For Blazor applications, see [instructions](./faq.yml#how-to-enable-feature-management-in-blazor-applications-or-as-scoped-services-in--net-applications) for enabling feature management as scoped services.
220
+
> [!NOTE]
221
+
> For Blazor applications, see [instructions](./faq.yml#how-to-enable-feature-management-in-blazor-applications-or-as-scoped-services-in--net-applications) for enabling feature management as scoped services.
264
222
265
223
## Targeting filter in action
266
224
@@ -280,10 +238,6 @@ The targeting filter evaluates a user's feature state based on the user's target
280
238
281
239
Now sign in as `[email protected]`, using the password you set when registering the account. The **Beta** item doesn't appear on the toolbar, because `[email protected]` is specified as an excluded user.
282
240
283
-
You can create more users with `@contoso.com` and `@contoso-xyz.com` email addresses to see the behavior of the group settings.
284
-
285
-
Users with `contoso-xyz.com` email addresses won't see the **Beta** item. While 50% of users with `@contoso.com` email addresses will see the **Beta** item, the other 50% won't see the **Beta** item.
286
-
287
241
## Next steps
288
242
289
243
To learn more about the feature filters, continue to the following documents.
Copy file name to clipboardExpand all lines: articles/azure-app-configuration/quickstart-feature-flag-dotnet-background-service.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -117,16 +117,16 @@ Add a feature flag called *Beta* to the App Configuration store and leave **Labe
117
117
using Microsoft.FeatureManagement;
118
118
```
119
119
120
-
1. Update the constructor of the `Worker` service to obtain instances of `IConfigurationRefresher` and `IFeatureManager` through dependency injection.
120
+
1. Update the constructor of the `Worker` service to obtain instances of `IConfigurationRefresher` and `IVariantFeatureManager` through dependency injection.
1. In **Create a new project**, filter on the **Console** project type and select **Console App**. If you want to create a .NET Framework app, please select **Console App (.NET Framework)** instead. Click **Next**.
43
+
1. In **Create a new project**, filter on the **Console** project type and select **Console App**. If you want to create a .NET Framework app, select **Console App (.NET Framework)** instead. Click **Next**.
44
44
45
-
1. In **Configure your new project**, enter a project name. If you are creating a .NET Framework app, please select **.NET Framework 4.7.2** or higher under **Framework**. Click **Create**.
45
+
1. In **Configure your new project**, enter a project name. If you're creating a .NET Framework app, select **.NET Framework 4.7.2** or higher under **Framework**. Click **Create**.
46
46
47
47
## Use the feature flag
48
48
@@ -77,7 +77,7 @@ You can use Visual Studio to create a new console app project.
77
77
78
78
IFeatureDefinitionProvider featureDefinitionProvider = new ConfigurationFeatureDefinitionProvider(configuration);
79
79
80
-
IFeatureManager featureManager = new FeatureManager(
80
+
IVariantFeatureManager featureManager = new FeatureManager(
81
81
featureDefinitionProvider,
82
82
new FeatureManagementOptions());
83
83
@@ -103,7 +103,7 @@ You can use Visual Studio to create a new console app project.
103
103
104
104
IFeatureDefinitionProvider featureDefinitionProvider = new ConfigurationFeatureDefinitionProvider(configuration);
105
105
106
-
IFeatureManager featureManager = new FeatureManager(
106
+
IVariantFeatureManager featureManager = new FeatureManager(
107
107
featureDefinitionProvider,
108
108
new FeatureManagementOptions());
109
109
@@ -130,7 +130,7 @@ You can use Visual Studio to create a new console app project.
0 commit comments