Posted on January 8, 2023
Feature flag can be used to enable disable specific functionalities of our application by turning a feature toggle on or off, without deploying code. Azure App Configuration provides a service to centrally manage application settings and feature flags. Modern programs, especially programs running in a cloud, generally have many components that are distributed in nature. Spreading configuration settings across these components can lead to hard-to-troubleshoot errors during an application deployment Please find the full code in github repository STEP 01: Create a Free Trail account in the Azure portal Start Free STEP 02: Navigate to App Configuration -> Create App Configuration STEP 03: Fill in the resource information and click “Review & Create”, make sure to select the Pricing tier “Free” STEP 04: Add feature flag through feature manager -> Create STEP 05: Find the access keys to make a connection through the .net core application
_Now let’s create a Console application where we will read this newly created feature flag and enable or disable a part of the code based on its value. _ The Last thing is to replace the {your_app_configuration_connection_string} with the connection string from the Azure App Configuration, which can be found under Settings -> Access keys. Please find the full code in github repositoryWhat is a feature flag?
What is Microsoft App Configuration?
There are many benefits when using feature flags. Below is a couple of them:
How to setup App Configuration in Azure
Create Console Application
Install the following NuGet Packages that our application will use:
Microsoft.Extensions.DependencyInjection
Microsoft.Azure.AppConfiguration.AspNetCore
Microsoft.FeatureManagement
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using Microsoft.FeatureManagement;
Console.WriteLine("Azure App Configuration Article Demo\n");
//Retrieve the Connection String from Azure App Configuration Resource
const string connectionString = "{Azure_App_ConnectionString}";
var configuration = new ConfigurationBuilder()
.AddAzureAppConfiguration(options =>
{
options.Connect(connectionString).UseFeatureFlags();
}).Build();
var services = new ServiceCollection();
services.AddSingleton<IConfiguration>(configuration).AddFeatureManagement();
using (var serviceProvider = services.BuildServiceProvider())
{
var featureManager = serviceProvider.GetRequiredService<IFeatureManager>();
//read great day feature
if (await featureManager.IsEnabledAsync("TogglePreviewFeature"))
{
Console.WriteLine("Preview Feature Enabled!!!");
}
else
{
Console.WriteLine("Preview Feature Disabled!");
}
};
Output