简体   繁体   中英

Feature management, feature toggle, feature flags not working with Azure App Configuration Store

I am trying to add feature flags to .net core 2.2 console app. The feature flags are defined on Azure App Configuration store.

When the feature flags are defined in the appsettings.json file, I faced a problem, but made it to work. The full console project is defined in my SO question here . This is not the problem.

I am trying to follow the tutorial and this is driving me nuts. The problem here is this tutorial is not simple. Its a web app, on the top of it, he used Secret manager tool .

I simply could not make the webapp work as described in the tutorial and so I am trying to first create a simple console app but so far could not succeed with Azure App Config store.

Here is the console app that did not work so far. Any help is deeply appreciated.

The following are packages are added to the console project.

  1. Microsoft.Extensions.Configuration.AzureAppConfiguration
  2. Microsoft.Extensions.Configuration.Json
  3. Microsoft.Extensions.DependencyInjection
  4. Microsoft.FeatureManagement
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.FeatureManagement;
using Microsoft.FeatureManagement.FeatureFilters;
using Microsoft.Extensions.Configuration.AzureAppConfiguration;

namespace ConfigurationConsoleApp
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var builder = new ConfigurationBuilder();
            var azureConnectionString = "<APP_CONFIGURATION_CONNECTION_STRING>";
            //builder.AddAzureAppConfiguration(options =>
            //{
            //    options.Connect(azureConnectionString).UseFeatureFlags();
            //});
            builder.AddAzureAppConfiguration(azureConnectionString);
            var config = builder.Build();
            Console.WriteLine(config["TestApp:Settings:Message"] ?? "Hello world!");
            var configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
            var services = new ServiceCollection();

            //services.AddSingleton<IConfiguration>(configuration).AddFeatureManagement().AddFeatureFilter<PercentageFilter>().AddFeatureFilter<AccountIdFilter>();
            services.AddSingleton<IConfiguration>(config).AddFeatureManagement();//.AddFeatureFilter<PercentageFilter>().AddFeatureFilter<AccountIdFilter>();

            const string FeatureName = "Beta";

            using (ServiceProvider serviceProvider = services.BuildServiceProvider())
            {
                var featureManager = serviceProvider.GetRequiredService<IFeatureManager>();
                var enabled = await featureManager.IsEnabledAsync(FeatureName);
                Console.WriteLine($"The {FeatureName} feature is {(enabled ? "enabled" : "disabled")} ");
            }
        }
    }
}


Did you take a look at the example apps in the Microsoft.FeatureManagement GitHub repository?

https://github.com/microsoft/FeatureManagement-Dotnet/tree/master/examples/FeatureFlagDemo https://github.com/microsoft/FeatureManagement-Dotnet/tree/master/examples/ConsoleApp

Your code looks like it should work. It won't work unless a feature flag is created in the Azure App Configuration instance named "Beta".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM