Routing

MVC Filters

MVC action filters can be set up to conditionally execute based on the state of a feature. This is done by registering MVC filters in a feature aware manner. The feature management pipeline supports async MVC Action filters, which implement IAsyncActionFilter.

services.AddMvc(o => 
{
    o.Filters.AddForFeature<SomeMvcFilter>(nameof(MyFeatureFlags.FeatureV));
});

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.

Conditional Middleware

Middleware can be conditionally executed by the use of feature flags

app.UseMiddlewareForFeature<ReferralTrackingMiddleware>("ReferralTracking");

With the above call, the application adds a middleware component that only appears in the request pipeline if the feature ReferralTracking is enabled. If the feature is enabled/disabled during runtime, the middleware pipeline can be changed dynamically.

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

app.UseForFeature("featureName", appBuilder => 
{
    appBuilder.UseMiddleware<T>();
});

Last updated