A simple way to start using feature toggles in .NET

Feature toggles are great - they can save time and make life easier in many situations. Sometimes you need to switch focus and work on something else within the same project. Sometimes you want to change the behaviour of a part of the code in a certain environment. Sometimes you want to release code that holds new features that are not yet ready to actually be used.

When used right, you can use feature toggles to separate releasing code and releasing new features - which is a wonderful thing!

In one of the projects I work on, we work in a very close team with the customer. The customer's focus and needs can switch fast depending on a number of factors, such as what their competitors are up to. Also, our system relies on a number of third-party systems that sometimes go down. Some of the systems are not crucial for the operation but whenever they go down, they are show-stoppers. Or at least they used to be.

Since this does not happen more than a couple of times a year, building some kind of admin UI where the customer could monitor and toggle these integrations is a bit overkill. Instead, I have created a simple but powerful FeatureToggle section in our configuration file. This lets us developers turn parts of our code on and off, depending on how the toggles are implemented.

Apart from being able to disable temporarily non-functioning code, we sometimes also use feature toggles to release new functionality without actually making it available at first. This way we can update our code and then make sure all other preparations are made before the functionality itself is enabled. Again, all of this without building an entire mechanism around it, it is no more than a configuration string and a couple of if's in the code.

I have published some sample code on my GitHub account that demonstrates a simple feature toggle implementation and how it is used. Check it out here: https://github.com/ilix/dot-net-feature-toggle

comments powered by Disqus