A custom ConfigurationReader implementation for FeatureFlags library Switcheroo which is a lightweight framework for feature toggling to enable trunk based development.
Switcheroo was created by Riaan Hanekom: github
Switcheroo aims for simplicity, with a clean syntax and a minimal feature set while not compromising on extensibility and testability.
Switcheroo.JsonFileConfigurationReader can be installed via Nuget.
> Install-Package Switcheroo.JsonFileConfigurationReader
Switcheroo.JsonFileConfigurationReader is licensed under the MIT license.
Installation
Nuget packages can be found here.
Add configuration as a json file e.g. features.json
[
{
"name": "testDateRange",
"enabled": true,
"from": "1 November 2012",
"until": "2 November 2012"
},
{
"name": "testDateRangeFromOnly",
"enabled": true,
"from": "1 November 2012"
},
{
"name": "testDateRangeUntilOnly",
"enabled": true,
"until": "2 November 2012"
},
{
"name": "testEstablished",
"established": true
},
{
"name": "testDependencies",
"enabled": true,
"dependencies": [
"testSimpleEnabled",
"testSimpleDisabled"
]
},
{
"name": "testSimpleEnabled",
"enabled": true
},
{
"name": "testSimpleDisabled",
"enabled": false
}
]
Initializing the library
Features.Initialize(x => x.FromSource(new JsonFileConfigurationReader("features.json")));
Checking feature status
if (Features.IsEnabled("testSimpleEnabled"))
{
// Implement feature
}
Boolean (true/false)
Feature toggles based on a static binary value - either on or off.
features.Add(new BooleanToggle("Feature1", true));
[
{
"name": "Feature1",
"enabled": true
}
]
Date Range (true/false, within date range)
Date Range feature toggles are evaluated on both the binary enabled value and the current date.
features.Add(new DateRangeToggle("Feature2", true, DateTime.Now.AddDays(5), null));
[
{
"name": "Feature2",
"enabled": true,
"from": "1 November 2012",
"until": "2 November 2012"
}
]
From and until dates can be any valid date format parseable by DateTime.Parse.
Established features
Marking a feature toggle as established makes the feature toggle throw a FeatureEstablishedException exception to make sure that it is not queried any more.
features.Add(new EstablishedFeatureToggle("establishedFeature"));
[
{
"name": "establishedFeature",
"established": true
}
]
Dependencies
Features can depend on other features. For instance, it is sometimes convenient to have a "main" feature, and then sub-features that depend on it. Dependencies can be specified in configuration as a comma delimited list.
var mainFeature = new BooleanToggle("mainFeature", true);
var subFeature1 = new BooleanToggle("subFeature1", true);
var subFeature2 = new BooleanToggle("subFeature2", true);
var dependency1 = new DependencyToggle(subFeature1, mainFeature);
var dependency2 = new DependencyToggle(subFeature2, mainFeature);
features.Add(dependency1);
features.Add(dependency2);
[
{
"name": "mainFeature",
"enabled": true,
"dependencies": [
"subFeature1",
"subFeature2"
]
},
{
"name": "subFeature1",
"enabled": true
},
{
"name": "subFeature2",
"enabled": true
}
]