-
Notifications
You must be signed in to change notification settings - Fork 0
FeatureOne.File
Ninja Sha!4h edited this page May 24, 2023
·
5 revisions
Feature toggles with File system Backend.
FeatureOne.File
package provides out of box File storage provider.
File support can easily be installed as a separate nuget package.
$ dotnet add package FeatureOne.File --version {latest}
Requires creating a feature file with JSON feature toggles as shown below.
File - Features.json
{
"gbk_dashboard": {
"toggle": {
"operator": "any",
"conditions": [{
"type": "simple",
"isEnabled": false
},
{
"type": "Regex",
"claim": "email",
"expression": "^[a-zA-Z0-9_.+-][email protected]"
}
]
}
},
"dashboard_widget": {
"toggle": {
"conditions": [{
"type": "simple",
"isEnabled": true
}]
}
}
}
See below bootstrap initialization for FeatureOne with SQL backend.
var configuration = new FileConfiguration
{
// Absolute path to the feature file.
FilePath ="C:\Work\Features.json",
// Enable cache with absolute expiry in Minutes.
CacheSettings = new CacheSettings
{
EnableCache = true,
Expiry = new CacheExpiry
{
InMinutes = 60,
Type = CacheExpiryType.Absolute
}
}
}
i. With File configuration.
var storageProvider = new FileStorageProvider(configuration);
Features.Initialize(() => new Features(new FeatureStore(configuration)));
ii. With Custom logger implementation, default is no logger.
var logger = new CustomLoggerImpl();
var storageProvider = new FileStorageProvider(configuration, logger);
Features.Initialize(() => new Features(new FeatureStore(storageProvider, logger), logger));
iii. With other overloads - Custom cache and Toggle Condition deserializer.
var toggleConditionDeserializer = CustomConditionDeserializerImpl(); // Implements IConditionDeserializer
var featureCache = CustomFeatureCache(); // Implements ICache
var storageProvider = new FileStorageProvider(configuration, featureCache, toggleConditionDeserializer);
Features.Initialize(() => new Features(new FeatureStore(storageProvider, logger), logger));
MIT License - Copyright (c) 2024 Ninja Sha!4h