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 https://blog.launchdarkly.com/tag/vsts/

Jacob Eapen Kochekkan

Senior Member Of Technical Staff at VMware

7 年

Will try this out.. thanks for the post !

Bas Hammendorp

?? Product Owner Mobiliteit @ Independer | ?? Connector of people, always on, gets energy from creative, valuable and efficient solutions!

7 年
回复

要查看或添加评论,请登录

Girish Goudar的更多文章

  • GitOps - Part 2

    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 条评论
  • Service Mesh - Istio Part 3

    Service Mesh - Istio Part 3

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

    1 条评论
  • Azure Arc- Data services

    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 - Part 1

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

  • Kubernetes Policy - Open Policy Agent

    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 - 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…

  • Service Mesh - Istio Part 2

    Service Mesh - Istio Part 2

    In the previous post, we looked at traffic management feature of istio . In this article we will take a brief look at…

  • Cluster API - Azure

    Cluster API - Azure

    This tool provides a consistent way of creating the kubernetes cluster across bare metal,onprem and various cloud…

  • Secure AKS cluster

    Secure AKS cluster

    When we create a Kubernetes cluster, by default the API server which expose the Kubernetes functionality is assigned a…

  • Service Mesh - Istio Part 1

    Service Mesh - Istio Part 1

    In this series of article, we will look at service mesh and what are the problems they solve. There are lot of service…

社区洞察

其他会员也浏览了