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-feature-filters-aspnet-core.md
+27-25Lines changed: 27 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,10 +5,10 @@ description: Learn how to use feature filters in Azure App Configuration to enab
5
5
ms.service: azure-app-configuration
6
6
ms.devlang: csharp
7
7
ms.custom: devx-track-csharp
8
-
author: maud-lv
9
-
ms.author: malev
8
+
author: zhiyuanliang
9
+
ms.author: zhiyuanliang
10
10
ms.topic: how-to
11
-
ms.date: 01/12/2024
11
+
ms.date: 02/28/2024
12
12
#Customerintent: As a developer, I want to create a feature filter to activate a feature flag depending on a specific scenario.
13
13
---
14
14
@@ -18,37 +18,40 @@ Feature flags allow you to activate or deactivate functionality in your applicat
18
18
19
19
In contrast, a _conditional feature flag_ allows the feature flag to be enabled or disabled dynamically. The application may behave differently, depending on the feature flag criteria. Suppose you want to show your new feature to a small subset of users at first. A conditional feature flag allows you to enable the feature flag for some users while disabling it for others. _Feature filters_ determine the state of the feature flag each time it's evaluated.
20
20
21
-
The `Microsoft.FeatureManagement` library includes three feature filters:
21
+
The `Microsoft.FeatureManagement` library includes four built-in feature filters:
22
22
23
23
-`PercentageFilter` enables the feature flag based on a percentage.
24
24
-`TimeWindowFilter` enables the feature flag during a specified window of time.
25
-
-`TargetingFilter`enables the feature flag for specified users and groups.
25
+
-`ContextualTargetingFilter` and `TargetingFilter`enable the feature flag for specified users and groups.
26
26
27
-
You can also create your own feature filter that implements the Microsoft.FeatureManagement.IFeatureFilter interface.
27
+
You can also create your own feature filter that implements the `Microsoft.FeatureManagement.IFeatureFilter` interface. For more information, see [Implementing a Feature Filter](https://github.com/microsoft/FeatureManagement-Dotnet?tab=readme-ov-file#implementing-a-feature-filter).
28
28
29
29
## Prerequisites
30
30
31
-
- An App Configuration store. [Create a store](./quickstart-azure-app-configuration-create.md#create-an-app-configuration-store).
31
+
- Follow the instructions in [Quickstart: Add feature flags to an ASP.NET Core app](./quickstart-feature-flag-aspnet-core.md) to create a web app with a feature flag.
32
+
-[Microsoft.FeatureManagement.AspNetCore 3.0.0 or later](https://www.nuget.org/packages/Microsoft.FeatureManagement.AspNetCore/4.0.0-preview)
32
33
33
-
## Register a feature filter
34
+
## Set up feature management
34
35
35
-
You register a feature filter by calling the `AddFeatureFilter` method, specifying the type name of the desired feature filter. For example, the following code registers `PercentageFilter`:
36
+
Since `Microsoft.FeatureManagement` 3.0.0, all built-in filters, except for the `TargetingFilter`, are added automatically when feature management is registered. For more information on using `TargetingFilter`, see [Enable staged rollout of features for targeted audiences](./howto-targetingfilter-aspnet-core.md).
## Configure a feature filter in Azure App Configuration
42
+
> [!TIP]
43
+
> You can create your own feature filters that implements the `Microsoft.FeatureManagement.IFeatureFilter` interface. The feature filters can be registered by calling the `AddFeatureFilter` method. For built-in feature filters, calling `AddFeatureFilter` is no longer needed since `Microsoft.FeatureManagement` 3.0.0.
44
+
>
45
+
> ```csharp
46
+
>services.AddFeatureManagement()
47
+
> .AddFeatureFilter<MyCriteriaFilter>();
48
+
> ```
46
49
47
-
Some feature filters have additional settings. For example, `PercentageFilter` activates a feature based on a percentage. It has a setting defining the percentage to use.
50
+
## Configure a feature filter in Azure App Configuration
48
51
49
-
You can configure these settings for feature flags defined in Azure App Configuration. For example, follow these steps to use `PercentageFilter` to enable the feature flag for 50% of requests to a web app:
1. Follow the instructions in [Quickstart: Add feature flags to an ASP.NET Core app](./quickstart-feature-flag-aspnet-core.md) to create a web app with a feature flag.
54
+
Youcanconfigurethesesettingsforfeature flags defined in Azure App Configuration. For example, follow these steps to use `TimeWindowFilter` to activate the feature flag at a certain moment:
52
55
53
56
1. In the Azure portal, go to your configuration store and select **Feature manager**.
54
57
@@ -60,26 +63,25 @@ You can configure these settings for feature flags defined in Azure App Configur
60
63
61
64
:::image type="content" source="./media/feature-filters/edit-a-feature-flag.png" alt-text="Screenshot of the Azure portal, filling out the form 'Edit feature flag'.":::
62
65
63
-
1. The pane **Create a new filter** opens. Under **Filter type**, select **Targeting filter** to enable a new filter for specific users or a group.
66
+
1. The pane **Create a new filter** opens. Under **Filter type**, select **Time window filter** to enable a new filter for a specific time window.
64
67
65
-
:::image type="content" source="./media/feature-filters/add-targeting-filter.png" alt-text="Screenshot of the Azure portal, creating a new targeting filter.":::
68
+
1. Set the **Expiry date** to **Never** and set the **Start date** to 10 minutes ahead of the current time. For example, if the current time is 1:50 PM on February 28, 2024, please set the time to 2 minutes later, which would be 2:00 PM.
69
+
70
+
:::image type="content" source="./media/feature-filters/add-time-window-filter.png" alt-text="Screenshot of the Azure portal, creating a new time window filter.":::
66
71
67
-
1. Optionally expand the **Evaluation flow** menu to see a graph showing how the targeting filter is evaluated in the selected scenario. Leave the **Default Percentage** at 50. The options **Override by Groups** and **Override by Users** let you enable or disable the feature flag for select groups or users. These options are disabled by default.
68
72
1. Select **Add** to save the new feature filter and return to the **Edit feature flag** screen.
69
73
70
74
1. The feature filter you created is now listed in the feature flag details. Select **Apply** to save the new feature flag settings.
71
75
72
-
:::image type="content" source="./media/feature-filters/feature-flag-edit-apply-filter.png" alt-text="Screenshot of the Azure portal, applying new targeting filter.":::
76
+
:::image type="content" source="./media/feature-filters/feature-flag-edit-apply-filter.png" alt-text="Screenshot of the Azure portal, applying new time window filter.":::
73
77
74
78
1. On the **Feature manager** page, the feature flag now has a **Feature filter(s)**valueof**1**.
75
79
76
80
:::imagetype="content"source="./media/feature-filters/updated-feature-flag.png"alt-text="Screenshot of the Azure portal, displaying updated feature flag.":::
77
81
78
82
## Feature filters in action
79
83
80
-
To see the effects of this feature flag, launch the application and hit the **Refresh** button in your browser multiple times. You'll see that the *Beta* item appears on the toolbar about 50% of the time. It's hidden the rest of the time, because the `PercentageFilter` deactivates the *Beta* feature for a subset of requests. The following video shows this behavior in action.
81
-
82
-
:::image type="content" source="./media/feature-filters/feature-flags-percentagefilter.gif" alt-text="Screenshot of a web browser showing a targeting filter in action.":::
84
+
Toseetheeffectsofthisfeatureflag, launchtheapplication. You'll see that the *Beta* item will not appears on the toolbar. It'shidden, becausethe `TimeWindowFilter` deactivatesthe*Beta*feature. Afterabout10minutes, clicktherefreshbuttoninyoubrowserandyou'll see the *Beta* item will appear again because the `TimeWindowFilter` will activate the *Beta* feature when time hits the time window.
0 commit comments