ASP.NET Core 3 Web Server. appsettings.json "FeatureManagement": { "RouteStrategy": false },
I'd like to get configuration and add route in the function. How to get the FeatureManager here to analyze what features IsEnabled?
public void ConfigureServices(IServiceCollection services)
{
services.AddFeatureManagement();
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddSingleton<WeatherForecastService>();
// <---------???
//
If I understand correctly, what you are asking is how to create a FeatureManager
without the dependency injection.
This was not possible at the time of your question but it is now possible since v3.1.0 : https://github.com/microsoft/FeatureManagement-Dotnet/releases/tag/3.1.0
You need to just read your configuration and then you can use ConfigurationFeatureDefinitionProvider
and FeatureManager
.
IConfiguration configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
var featureDefintionProvider = new ConfigurationFeatureDefinitionProvider(configuration);
var featureManager = new FeatureManager(featureDefintionProvider)();
bool isRouteStrategyEnabled = await featureManager.IsEnabledAsync("RouteStrategy");