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: README.md
+20-28Lines changed: 20 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -142,7 +142,6 @@ In the above example, `FeatureW` specifies a `RequirementType` of `All`, meaning
142
142
143
143
### Status
144
144
145
-
146
145
`Status` is an optional property of a feature flag that controls how a flag's enabled state is evaluated. By default, the status of a flag is `Conditional`, meaning that feature filters should be evaluated to determine if the flag is enabled. If the `Status` of a flag is set to `Disabled` then feature filters are not evaluated and the flag is always considered to be disabled.
147
146
148
147
@@ -158,21 +157,7 @@ In the above example, `FeatureW` specifies a `RequirementType` of `All`, meaning
158
157
```
159
158
160
159
In this example, even though the `AlwaysOn` filter would normally always make the feature enabled, the `Status` property is set to `Disabled`, so this feature will always be disabled.
161
-
162
-
### Referencing
163
-
164
-
To make it easier to reference these feature flags in code, we recommend to define feature flag variables like below.
165
-
166
-
```C#
167
-
// Define feature flags in an enum
168
-
publicenumMyFeatureFlags
169
-
{
170
-
FeatureT,
171
-
FeatureU,
172
-
FeatureV
173
-
}
174
-
```
175
-
160
+
176
161
### Service Registration
177
162
178
163
Feature flags rely on .NET Core dependency injection. We can register the feature management services using standard conventions.
@@ -194,7 +179,6 @@ public class Startup
194
179
195
180
This tells the feature manager to use the "FeatureManagement" section from the configuration for feature flag settings. It also registers two built-in feature filters named `PercentageFilter` and `TimeWindowFilter`. When filters are referenced in feature flag settings (appsettings.json) the _Filter_ part of the type name can be omitted.
196
181
197
-
198
182
**Advanced:** The feature manager looks for feature definitions in a configuration section named "FeatureManagement". If the "FeatureManagement" section does not exist, it falls back to the root of the provided configuration.
199
183
200
184
## Consumption
@@ -207,7 +191,7 @@ The basic form of feature management is checking if a feature is enabled and the
207
191
…
208
192
IFeatureManagerfeatureManager;
209
193
…
210
-
if (awaitfeatureManager.IsEnabledAsync(nameof(MyFeatureFlags.FeatureU)))
194
+
if (awaitfeatureManager.IsEnabledAsync("FeatureX"))
211
195
{
212
196
// Do something
213
197
}
@@ -236,7 +220,7 @@ The feature management library provides functionality in ASP.NET Core and MVC to
236
220
MVC controller and actions can require that a given feature, or one of any list of features, be enabled in order to execute. This can be done by using a `FeatureGateAttribute`, which can be found in the `Microsoft.FeatureManagement.Mvc` namespace.
237
221
238
222
```C#
239
-
[FeatureGate(MyFeatureFlags.FeatureX)]
223
+
[FeatureGate("FeatureX")]
240
224
publicclassHomeController : Controller
241
225
{
242
226
…
@@ -246,14 +230,14 @@ public class HomeController : Controller
246
230
The `HomeController` above is gated by "FeatureX". "FeatureX" must be enabled before any action the `HomeController` contains can be executed.
247
231
248
232
```C#
249
-
[FeatureGate(MyFeatureFlags.FeatureY)]
233
+
[FeatureGate("FeatureX")]
250
234
publicIActionResultIndex()
251
235
{
252
236
returnView();
253
237
}
254
238
```
255
239
256
-
The `Index` MVC action above requires "FeatureY" to be enabled before it can execute.
240
+
The `Index` MVC action above requires "FeatureX" to be enabled before it can execute.
257
241
258
242
### Disabled Action Handling
259
243
@@ -271,11 +255,19 @@ public interface IDisabledFeaturesHandler
271
255
In MVC views `<feature>` tags can be used to conditionally render content based on whether a feature is enabled or not.
272
256
273
257
```HTML+Razor
274
-
<feature name=@nameof(MyFeatureFlags.FeatureX)>
258
+
<feature name="FeatureX">
275
259
<p>This can only be seen if 'FeatureX' is enabled.</p>
276
260
</feature>
277
261
```
278
262
263
+
You can also negate the tag helper evaluation to display content when a feature or set of features are disabled. By setting `negate="true"` in the example below, the content is only rendered if `FeatureX` is disabled.
264
+
265
+
```HTML+Razor
266
+
<feature negate="true" name="FeatureX">
267
+
<p>This can only be seen if 'FeatureX' is disabled.</p>
268
+
</feature>
269
+
```
270
+
279
271
The `<feature>` tag requires a tag helper to work. This can be done by adding the feature management tag helper to the _ViewImports.cshtml_ file.
The code above adds an MVC filter named `SomeMvcFilter`. This filter is only triggered within the MVC pipeline if the feature it specifies, "FeatureV", is enabled.
288
+
The code above adds an MVC filter named `SomeMvcFilter`. This filter is only triggered within the MVC pipeline if the feature it specifies, "FeatureX", is enabled.
297
289
298
290
### Razor Pages
299
291
MVC Razor pages can require that a given feature, or one of any list of features, be enabled in order to execute. This can be done by using a `FeatureGateAttribute`, which can be found in the `Microsoft.FeatureManagement.Mvc` namespace.
300
292
301
293
```C#
302
-
[FeatureGate(MyFeatureFlags.FeatureU)]
294
+
[FeatureGate("FeatureX")]
303
295
publicclassIndexModel : PageModel
304
296
{
305
297
publicvoidOnGet()
@@ -308,7 +300,7 @@ public class IndexModel : PageModel
308
300
}
309
301
```
310
302
311
-
The code above sets up a Razor page to require the "FeatureU" to be enabled. If the feature is not enabled, the page will generate an HTTP 404 (NotFound) result.
303
+
The code above sets up a Razor page to require the "FeatureX" to be enabled. If the feature is not enabled, the page will generate an HTTP 404 (NotFound) result.
312
304
313
305
When used on Razor pages, the `FeatureGateAttribute` must be placed on the page handler type. It cannot be placed on individual handler methods.
314
306
@@ -317,10 +309,10 @@ When used on Razor pages, the `FeatureGateAttribute` must be placed on the page
317
309
The feature management library can be used to add application branches and middleware that execute conditionally based on feature state.
With the above call, the application adds a middleware component that only appears in the request pipeline if the feature "FeatureU" is enabled. If the feature is enabled/disabled during runtime, the middleware pipeline can be changed dynamically.
315
+
With the above call, the application adds a middleware component that only appears in the request pipeline if the feature "FeatureX" is enabled. If the feature is enabled/disabled during runtime, the middleware pipeline can be changed dynamically.
324
316
325
317
This builds off the more generic capability to branch the entire application based on a feature.
/// A filter that uses the feature management context to ensure that the current task has the notion of an account id, and that the account id is allowed.
9
+
/// This filter will only be executed if an object implementing <see cref="IAccountContext"/> is passed in during feature evaluation.
/// A filter that uses the feature management context to ensure that the current task has the notion of an account id, and that the account id is allowed.
15
-
/// This filter will only be executed if an object implementing <see cref="IAccountContext"/> is passed in during feature evaluation.
0 commit comments