Feature toggling using ASP.NET

Feature toggling is a technique in software development that attempts to provide an alternative to maintaining multiple source-code branches (known as feature branches), such that the feature can be tested, even before it is completed and ready for release. — Wikipedia

I have already write about feature toggling in this article. The following post describes how to implementing feature toggling using ASP.NET.

Setup the project

The following demo uses the Feature Toggle NuGet package developed by Jason Roberts . At time of writing, the package is NOT compatible with ASP.NET Core version (details here: https://github.com/jason-roberts/FeatureToggle/issues/121).

You can download and install Visual studio Community from here, and create a new project. To add the FeatureToggle package to your solution type

PM> Install-Package FeatureToggle

inside the Package manager console.

General pattern

The FeatureToggle package implements a strongly typed pattern, here’s an typical usage schema:

An strongly typed pattern avoid runtime execution errors caused by constant and magic strings. The IFeatureToggle interface defines the structure of the Toggle class, the IFeatureProvider defines the configuration location and the configuration store.

Creating Your Own Custom Toggles

To create your own custom toggle is necessary implement IFeatureToggle. You can also customize the provider behavoir by override the ToggleValueProvider property.

Using Feature Toggle

Using FeatureToggle plugin is very simple, you need create a new class in your project which extend one of Toggle classes, each Toggle class has a specific behavoir, here’s a list of default toggles. The following snippet uses the SimpleFeatureToggle class:

The SimpleFeatureToggle class reads the web.config file of the project to detect if the feature is enabled or not:

Final thought

Here’s more information about the FeatureToggle package. It is very useful to implement standard feature toggling and custom feature toggling behaviours.

For an overview on Feature Toggling, click here.

Cheers :)

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.