How to implement a feature toggle in C#

Take advantage of feature toggles to manage application features without having to maintain multiple source code branches

Become An Insider

Sign up now and get FREE access to hundreds of Insider articles, guides, reviews, interviews, blogs, and other premium content. Learn more.

Feature toggling is a nice concept that facilitates trunk-based development. You can use feature toggles (also known as feature switches, feature flags, and feature flippers) to test a new feature in the main branch even before it is ready for release. Feature flags have many other uses as well, such as hiding advanced features from users of a free or basic version of an application. 

Feature toggles allow you to keep your production-ready code base and your development code base more closely in sync. Depending on the dynamicity and durability of a feature, you can draw on different kinds of toggles such as release toggles, experimental toggles, permissioning toggles, and ops toggles, to name a few.

This article presents an overview of feature toggling and how we can adopt this technique to manage features in our applications without having to manage and maintain and (even more daunting) eventually merge multiple source code branches.

Feature toggle libraries for .Net

Implementing feature toggling isn’t difficult. There are many feature toggle libraries in .Net to choose from including NFeature, nToggle, FeatureToggle, and FeatureSwitcher. Of these, I prefer using the open source FeatureToggle library written by Jason Roberts. FeatureToggle is simple, easy to use, and extensible. You can take advantage of this library to implement standard or custom feature toggling in your application with ease. Note that you can use FeatureToggle with .Net Core applications as well.

To continue reading this article register now