If you find this library useful, cup of coffee would be awesome! You can support further development of the library via Paypal.
Have you ever wrote the code like following to verify that either you have to disable or enable some functionality base on set of conditions (usually different sources):
if(ConfigurationManager.AppSettings["MyKey"] == "true")
return ...;
or something like this:
if(HttpContext.Current != null && HttpContext.Current.Session != null && HttpContext.Current.Session["MyKey"] == "true")
return ...;
FeatureSwitch library should reduce amount of time and code needed to implement feature toggle in unified way. FeatureSwitch library is easily adoptable and extendable.
FeatureSwitch library is based on two basic aspects features and strategies. In combination they provide enough input data for feature set builder to construct feature context to be used later to check whether particular feature is enabled or disabled. Currently there are following additional integrations:
- Mvc Control Panel - FeatureSwitch UI Control Panel
- Web Optimization - Helpers for styles and scripts conditional bundling and minification
- EPiServer integration - Module to integrate into EPiServer CMS platform for easier access to UI Control Panel
Feature is main aspect of FeatureSwitch library it's your logical feature representation - either it's enabled or disabled. You will need to define your features to work with FeatureSwitch library.
To define your feature you have to create class that inherits from FeatureSwitch.BaseFeature
class:
public class MySampleFeature : FeatureSwitch.BaseFeature
{
}
Keep in mind that you will need to add at least one strategy for the feature in order to enable it. By default every feature is disabled.
To get started with FeatureSwitch you need to kick-off FeatureSetBuilder by calling Build()
instance method:
var builder = new FeatureSetBuilder();
builder.Build();
By calling Build
method you are triggering auto-discovery of features in current application domain loaded assemblies. Auto-discovery will look for classes inheriting from FeatureSwitch.BaseFeature
class. Those are assumed to be features.
After features have been discovered and set has been built you are able to check whether feature is enabled or not:
var isEnabled = FeatureContext.IsEnabled<MySampleFeature>();
You can also use some of the IsEnabled
overloads for other usages.
All packages are available on NuGet feeds:
- Core library
- Asp.Net Mvc Integration
- Asp.Net Mvc 5 Integration / Owin
- Web Optimization pack
- EPiServer integration
More information on extending FeatureSwitch library.