Feature Flags in .Net

Feature Flags in .Net

In DevOps era, where we want to do continuous releases and where feature branches are created only for pull requests and not for long lived feature development. We need to use feature flags.

Feature flagging allows developers to take full control of their feature lifecycles independent of code deployments. Application features can be enabled or disabled without requiring code to be reverted or redeployed.

It also enables us to deploy the features to only certain users of the application Instead of rolling out features at once to all the users of the application.

We can implement feature toggle without using third party tools by just having the Feature Toggle specified in the web.config and checking the visibility of the feature based on the value specified in web.config.

This has a drawback that it does not provide a compile time check in case we do not specify the corerct Feature Toggle values and hence these issues only are reported in run time

So we can use open source library Feature Toggles and paid library LaunchDarkly

Feature Toggles

We can use the FeatureToggle nuget package available to implement feature toggle in our application

https://www.nuget.org/packages/FeatureToggle/

We need to add the feature toggle configuration value in web.config as specified below

<appSettings>
    <add key="FeatureToggle.HideAlbumsFeatureToggle" value="false" />
  </appSettings>

Create a class and inherit based on the type of toggle as shown below. This class will know how to read the configuration value from web.config 

using FeatureToggle.Toggles;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
 
namespace MvcMusicStore.FeaturetoggleSwitches
{
    public class HideAlbumsFeatureToggle : SimpleFeatureToggle
    {
    }
}

Next we will get initialize the class in a property as shown below

public HideAlbumsFeatureToggle HideAlbumsFeatureToggle {
            get
            {
                return new HideAlbumsFeatureToggle();
            }
                
        }

Next we will enable or disable the feature using the FeatureEnabled property as shown below

 
<ul id="album-list">
    @foreach (var album in Model)
    {
        if (album.HideAlbumsFeatureToggle.FeatureEnabled)
        {
 
        <li><a href="@Url.Action("Details", "Store",
                new { id = album.AlbumId })">
 
            <img alt="@album.Title" src="@album.AlbumArtUrl" />
            <span>@album.Title</span> </a>
        </li>
            }
        }
</ul>

LaunchDarkly

You can also control the feature flag centrally and can be managed by non-developers and which fully integrates with VSTS by using the LaunckDarkly extension specified here http://blog.launchdarkly.com/tag/vsts/

To view or add a comment, sign in

More articles by Girish Goudar

  • GPT‑5.5 Is Released — Powered by NVIDIA

    OpenAI has released GPT‑5.5, its latest frontier model — raising the bar for AI agents, reasoning, and enterprise‑scale…

  • 🚀From Emergent Agent Architectures to Enterprise Grade Platforms

    We’re seeing a clear shift in how AI agents are being designed—and more importantly, where trust is placed. Modern…

  • Reimagining Enterprise Infrastructure with AI-Powered Inner Loop Development

    The use of AI in enterprise platform teams is accelerating—but are we leveraging it the right way? Most developers in…

  • Dev Automation with MCP Server in VS Code

    Just explored how easy it is to configure an MCP (Model Context Protocol) server using VS Code Insiders — and it’s a…

  • GitOps - Part 2

    In the previous post, we looked at how to use fluxv2 for deploying apps through helm and kustomization. In this we will…

    2 Comments
  • Service Mesh - Istio Part 3

    Modern applications and platforms are distributed and deployed across data center, cloud and edge. Service mesh…

    1 Comment
  • Azure Arc- Data services

    Azure Arc enable to us manage VM's, Kubernetes, SQL and Data services of Azure deployed to any cloud or data center in…

  • Cert-Manager - Part 1

    Cert-manager automates the management of certificates within Kubernetes. It can be integrated with existing…

  • Kubernetes Policy - Open Policy Agent

    Open Policy Agent(OPA) is a general purpose declaratively policy engine which can be used for applying policy across…

  • GitOps - Part 1

    GitOps provides a way to declare the state of the cluster as code and make it so. This ensures that there is no drift…

Others also viewed

Explore content categories