Created
January 19, 2020 18:43
-
-
Save kasunkv/ec9b633c0d4c7df2efb98a3ea4a8aa8f to your computer and use it in GitHub Desktop.
Custom implementation for IDisabledFeaturesHandler
This file contains hidden or 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 Microsoft.AspNetCore.Mvc; | |
using Microsoft.AspNetCore.Mvc.Filters; | |
using Microsoft.FeatureManagement.Mvc; | |
using MusicStore.Web.Models; | |
using System; | |
using System.Collections.Generic; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Mvc.ViewFeatures; | |
using Microsoft.AspNetCore.Mvc.ModelBinding; | |
namespace MusicStore.Web.FeatureManagement | |
{ | |
public class MusicStoreDisabledFeaturesHandler : IDisabledFeaturesHandler | |
{ | |
public Task HandleDisabledFeatures(IEnumerable<string> features, ActionExecutingContext context) | |
{ | |
var vm = new DisabledFeatureViewModel | |
{ | |
FeatureName = string.Join(", ", features), | |
GoLiveDate = DateTimeOffset.UtcNow.AddDays(30) | |
}; | |
var viewResult = new ViewResult | |
{ | |
ViewName = "Views/Error/DisabledFeature.cshtml", | |
ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary()) | |
{ | |
Model = vm | |
} | |
}; | |
context.Result = viewResult; | |
return Task.CompletedTask; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment