Hi, I'm Nicholas 👋

I'm a Senior Platform Engineer

Buy Me A Coffee

Using Azure App Configuration Feature Flags with Dotnet Application

Date published:

Introduction

What is Azure App Configuration and Feature Flags

Azure App Configuration is a service that provides a central place to manage application settings and feature flags. Feature flags are a powerful technique for controlling the release of new functionality in your application. They allow you to turn features on or off for specific users or groups without deploying new code.

In this blog post, we’ll explore how to use Azure App Configuration feature flags with a .NET Core application.

Prerequisites

Before we get started, you’ll need the following:

Creating an Azure App Configuration instance

Open the Azure portal and sign in with your Azure account. In the left-hand menu, click on “Create a resource”. Type “App Configuration” in the search bar and select “App Configuration” from the results. Click on “Create”. Add a name for your App Configuration instance and select a subscription, resource group, and location. Click on “Create” to create your App Configuration instance.

Adding Feature Flags to your application

public void ConfigureServices(IServiceCollection services)
{
 services.AddControllers();
 services.AddFeatureManagement();
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseRouting();

app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }

In your appsettings.json file, add the following configuration: { "AzureAppConfiguration": { "ConnectionString": "<your-connection-string>" }, "FeatureManagement": { "CacheExpirationInterval": "30", "DataStoreType": "AzureAppConfiguration" } }

In your code, retrieve a feature flag value using the following code: if (await HttpContext.Features.IsEnabledAsync("MyFeature")) { // Feature is enabled } else { // Feature is disabled }

Using Feature Flags in your application

Feature flags are a powerful technique for controlling your application’s release of new functionality. They allow you to turn features on or off for specific users or groups without deploying new code.

In your code, retrieve a feature flag value using the following code:

if (await HttpContext.Features.IsEnabledAsync("MyFeature"))
{
 // Feature is enabled
}
else
{
 // Feature is disabled
}

You can also use feature flags in Razor views using the following code:

@if (await FeatureManager.IsEnabledAsync("MyFeature")) { <p>This feature is enabled!</p> } else { <p>This feature is disabled.</p> }

Conclusion

In this blog post, we’ve explored how to use Azure App Configuration feature flags with a .NET Core application. Feature flags are a powerful technique for controlling your application’s release of new functionality. They allow you to turn features on or off for specific users or groups without deploying new code. In this blog post, we’ve explored how to use Azure App Configuration feature flags with a .NET Core application.

References