Last active
April 24, 2019 20:12
-
-
Save JanneMattila/19cd4f4a0db892cdf964ed1739032fed to your computer and use it in GitHub Desktop.
Azure App Configuration
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 FeatureTogglerApp.Features; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.Extensions.Options; | |
namespace FeatureTogglerApp.Controllers | |
{ | |
[Route("api/[controller]")] | |
[ApiController] | |
public class DataController : ControllerBase | |
{ | |
private readonly FeatureOptions _featureOptions; | |
public DataController(IOptionsSnapshot<FeatureOptions> featureOptions) | |
{ | |
_featureOptions = featureOptions.Value; | |
} | |
[HttpGet] | |
public IEnumerable<string> Get() | |
{ | |
var user = "janne"; // DEMO: Example user to look for feature flags | |
// Use app level toggles and if that is not enabled | |
// then use toggle from user level (optional) | |
var dataApiEnabled = | |
_featureOptions.DataApiEnabled || | |
(_featureOptions.Users.ContainsKey(user) && | |
_featureOptions.Users[user].DataApiEnabled); | |
if (dataApiEnabled) | |
{ | |
return new string[] { "cool", "api", "in", "use" }; | |
} | |
else | |
{ | |
return new string[] { /* None since api not in use. */ }; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment