Created
June 12, 2019 21:56
-
-
Save chivandikwa/087aacdeb0505369ae8de0e40bdbda9b to your computer and use it in GitHub Desktop.
Some custom IDisabledFeaturesHandler implementations (Microsoft.FeatureManagement and Microsoft.FeatureManagement.AspNetCore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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