Skip to content

Commit 39bc3ed

Browse files
Update the recommended way to reference feature flag name in README (#275)
* update the recommended way to reference feature flag name * remove nameof * remove recommended referencing way * using string literals directly
1 parent f189d9f commit 39bc3ed

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

README.md

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,6 @@ A `RequirementType` of `All` changes the traversal. First, if there are no filte
138138
```
139139

140140
In the above example, `FeatureW` specifies a `RequirementType` of `All`, meaning all of it's filters must evaluate to true for the feature to be enabled. In this case, the feature will be enabled for 50% of users during the specified time window.
141-
142-
### Referencing
143-
144-
To make it easier to reference these feature flags in code, we recommend to define feature flag variables like below.
145-
146-
``` C#
147-
// Define feature flags in an enum
148-
public enum MyFeatureFlags
149-
{
150-
FeatureT,
151-
FeatureU,
152-
FeatureV
153-
}
154-
```
155141

156142
### Service Registration
157143

@@ -187,7 +173,7 @@ The basic form of feature management is checking if a feature is enabled and the
187173
188174
IFeatureManager featureManager;
189175
190-
if (await featureManager.IsEnabledAsync(nameof(MyFeatureFlags.FeatureU)))
176+
if (await featureManager.IsEnabledAsync("FeatureX"))
191177
{
192178
// Do something
193179
}
@@ -216,7 +202,7 @@ The feature management library provides functionality in ASP.NET Core and MVC to
216202
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.
217203

218204
``` C#
219-
[FeatureGate(MyFeatureFlags.FeatureX)]
205+
[FeatureGate("FeatureX")]
220206
public class HomeController : Controller
221207
{
222208
@@ -226,14 +212,14 @@ public class HomeController : Controller
226212
The `HomeController` above is gated by "FeatureX". "FeatureX" must be enabled before any action the `HomeController` contains can be executed.
227213

228214
``` C#
229-
[FeatureGate(MyFeatureFlags.FeatureY)]
215+
[FeatureGate("FeatureX")]
230216
public IActionResult Index()
231217
{
232218
return View();
233219
}
234220
```
235221

236-
The `Index` MVC action above requires "FeatureY" to be enabled before it can execute.
222+
The `Index` MVC action above requires "FeatureX" to be enabled before it can execute.
237223

238224
### Disabled Action Handling
239225

@@ -251,7 +237,7 @@ public interface IDisabledFeaturesHandler
251237
In MVC views `<feature>` tags can be used to conditionally render content based on whether a feature is enabled or not.
252238

253239
``` HTML+Razor
254-
<feature name=@nameof(MyFeatureFlags.FeatureX)>
240+
<feature name="FeatureX">
255241
<p>This can only be seen if 'FeatureX' is enabled.</p>
256242
</feature>
257243
```
@@ -277,17 +263,17 @@ The feature management pipeline supports async MVC Action filters, which impleme
277263
``` C#
278264
services.AddMvc(o =>
279265
{
280-
o.Filters.AddForFeature<SomeMvcFilter>(nameof(MyFeatureFlags.FeatureV));
266+
o.Filters.AddForFeature<SomeMvcFilter>("FeatureX");
281267
});
282268
```
283269

284-
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.
270+
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.
285271

286272
### Razor Pages
287273
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.
288274

289275
``` C#
290-
[FeatureGate(MyFeatureFlags.FeatureU)]
276+
[FeatureGate("FeatureX")]
291277
public class IndexModel : PageModel
292278
{
293279
public void OnGet()
@@ -296,7 +282,7 @@ public class IndexModel : PageModel
296282
}
297283
```
298284

299-
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.
285+
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.
300286

301287
When used on Razor pages, the `FeatureGateAttribute` must be placed on the page handler type. It cannot be placed on individual handler methods.
302288

@@ -305,10 +291,10 @@ When used on Razor pages, the `FeatureGateAttribute` must be placed on the page
305291
The feature management library can be used to add application branches and middleware that execute conditionally based on feature state.
306292

307293
``` C#
308-
app.UseMiddlewareForFeature<ThirdPartyMiddleware>(nameof(MyFeatureFlags.FeatureU));
294+
app.UseMiddlewareForFeature<ThirdPartyMiddleware>("FeatureX");
309295
```
310296

311-
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.
297+
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.
312298

313299
This builds off the more generic capability to branch the entire application based on a feature.
314300

0 commit comments

Comments
 (0)