Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementation of feature flags in C#

Feature flags are something I often use but never really gave much thought about it until this new project I'm working on started.

I usually implement it with lots of keys in my web.config file but this approach has two major drawbacks:

  1. When changing a value inside web.config the application pool is restarted - This can be a problem in a heavy access environment
  2. Having too many keys in the web.config file is confusing and can get pretty messy

What's the best way to overcome these problems?

like image 260
tucaz Avatar asked Jan 22 '13 12:01

tucaz


1 Answers

I would suggest using IoC to abstract away the implementation of your feature flags - all your code needs to access is something along the lines of IFeatures.IsEnabled("FeatureA"). Once you've done this, you can choose the most sensible implementation - some suggestions below:

  • web.config implementation (compatible with what you have now)
  • Database implementation (with cached values, possibly using SqlDependency if you want to work on a web farm)
  • Separate configuration file implementation (cached, but using a FileSystemWatcher to check for changes to the config file and load them without needing to restart the app pool). This allows for the case when you need features defined before you need your DB.
like image 117
Richard Avatar answered Sep 26 '22 08:09

Richard