A FeatureToggle is a way of making code more releasable by
- Hiding unfinished features behind a "toggle"
- Releasing new features gradually, by letting only a subset of users use the feature
Read Martin Fowlers blog post called FeatureToggle, for more background.
<configuration>
<configSections>
<section name="featureToggle" type="AspNetFeatureToggle.Configuration.FeatureToggleSection, FeatureToggle"/>
</configSections>
<featureToggle>
<featureList>
<add name="AFeature" enabled="true" />
</featureList>
</featureToggle>
</configuration>
if (FeatureToggle.IsEnabled("AFeature"))
{
// Do the new stuff
}
else
{
// Do the old stuff
}
This can be done in two ways:
- Specify a list of users that can access the feature
<featureList>
<add name="AFeature" enabled="true" userListPath="AFeature_Users.config" />
</featureList>
if (FeatureToggle.IsEnabled(<feature name>, <user name>))
{
// Do the new stuff
}
else
{
// Do the old stuff
}
- Users can be randomly chosen, for example for A/B testing or canary releasing
<featureList>
<add name="AFeature" enabled="true" randomFactor="0.1" />
</featureList>
randomFactor = 0.1 means 10% of requests will have the feature enabled. 0.5 is 50% and so on.
Useful lessons learned about feature toggles from this [InfoQ talk] (http://www.infoq.com/presentations/Feature-Bits)
- Limit the number of FeatureToggles
- A FeatureToggle should have a short lifetime
- Have as few places as possible where code is wrapped, preferrably only one per FeatureToggle.
- Use a naming convention