Created
January 16, 2020 16:06
-
-
Save kasunkv/060b49c00eff1f7a9bb64abb1ff592e5 to your computer and use it in GitHub Desktop.
Using IFeatureManager to access feature flags
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.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