Skip to content

Instantly share code, notes, and snippets.

@kasunkv
Created January 16, 2020 16:06
Show Gist options
  • Save kasunkv/060b49c00eff1f7a9bb64abb1ff592e5 to your computer and use it in GitHub Desktop.
Save kasunkv/060b49c00eff1f7a9bb64abb1ff592e5 to your computer and use it in GitHub Desktop.
Using IFeatureManager to access feature flags
using Microsoft.FeatureManagement.Mvc;
namespace MusicStore.Web.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly IAlbumService _albumService;
private readonly IFeatureManager _featureManager;
public HomeController(IAlbumService albumService, IFeatureManagerSnapshot featureManager, ILogger<HomeController> logger)
{
_albumService = albumService;
_featureManager = featureManager;
_logger = logger;
}
public async Task<IActionResult> Index()
{
var vm = new HomeViewModel();
vm.Featured = _albumService.AllAlbums();
// Check if the UserSuggestion feature is enabled.
if (await _featureManager.IsEnabledAsync(Features.UserSuggestions))
{
vm.Suggestions = _albumService.UserPreferenceAlbums();
}
return View(vm);
}
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment