Skip to content

Instantly share code, notes, and snippets.

@chivandikwa
Created June 12, 2019 21:56
Show Gist options
  • Save chivandikwa/087aacdeb0505369ae8de0e40bdbda9b to your computer and use it in GitHub Desktop.
Save chivandikwa/087aacdeb0505369ae8de0e40bdbda9b to your computer and use it in GitHub Desktop.
Some custom IDisabledFeaturesHandler implementations (Microsoft.FeatureManagement and Microsoft.FeatureManagement.AspNetCore
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.FeatureManagement;
namespace FeatureManagementRecipes.Features
{
internal class DisabledFeaturesActionHandler : IDisabledFeaturesHandler
{
private readonly Action<IEnumerable<string>, ActionExecutingContext> _handler;
public DisabledFeaturesActionHandler(
Action<IEnumerable<string>, ActionExecutingContext> handler)
{
Action<IEnumerable<string>, ActionExecutingContext> action = handler;
_handler = action ?? throw new ArgumentNullException(nameof (handler));
}
public Task HandleDisabledFeatures(IEnumerable<string> disabledFeatures, ActionExecutingContext context)
{
_handler(disabledFeatures, context);
return Task.CompletedTask;
}
}
}
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.FeatureManagement;
namespace FeatureManagementRecipes.Features
{
public class DisabledFeaturesRedirectHandler: IDisabledFeaturesHandler
{
private readonly string _redirectUri;
public DisabledFeaturesRedirectHandler(string redirectUri)
{
_redirectUri = redirectUri;
}
public Task HandleDisabledFeatures(IEnumerable<string> disabledFeatures, ActionExecutingContext context)
{
context.Result = new RedirectResult(_redirectUri);
return Task.CompletedTask;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment