The features can be enabled by
- Cookies
- Headers
- QueryString
// appsettings.json
"FeatureManagement": {
"FeatureA": false,
"FeatureB": false,
"FeatureC": {
"EnabledFor": [
{
"Name": "Cookies"
},
{
"Name": "QueryString"
}
]
},
"FeatureD": {
"EnabledFor": [
{
"Name": "Cookies"
}
]
}
}
// Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpContextAccessor();
services.AddMvc();
services.AddFeatureManagement()
.AddFeatureFilter<CookiesFilter>()
.AddFeatureFilter<HeadersFilter>()
.AddFeatureFilter<QueryStringFilter>();
}
private readonly IFeatureManager featureManager;
public DummyClass(IFeatureManager featureManager)
{
this.featureManager = featureManager;
}
private const string FeatureName = "FeatureC";
public async Task DummyMethod()
{
if(await this.featureManager.IsEnabledAsync(FeatureName))
{
// Do something
}
}
dotnet build
dotnet test
Turn on by querystring
dotnet run --project .\src\Dianper.FeatureToggle\Dianper.FeatureToggle.Sample
http://localhost:55715/api/values?FeatureC=true