Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Home
- Introduction
- What are Feature Toggles?
- Benefits of Feature Toggles
- Getting Started
- Core Concepts
- Architecture Overview
- Installation
- Basic Usage
- Dependency Injection Integration ⭐ NEW v5.1.0
- Storage Providers
- Condition Types
- Advanced Configuration
- Extending FeatureOne
- Best Practices
- Troubleshooting
- API Reference
FeatureOne is a powerful .NET library designed to implement feature toggles (also known as feature flags) in your applications. With FeatureOne, you can control the visibility and behavior of application features at runtime without deploying new code, enabling safer releases, gradual rollouts, and better control over feature exposure.
This library supports .NET Framework 4.6.2, .NET Standard 2.1, and .NET 9.0, making it compatible with a wide range of .NET applications.
A feature toggle (or feature flag) is a software engineering technique that allows you to turn application features "on" or "off" remotely without requiring a code deployment. This is achieved by wrapping new functionality in conditional statements that check the status of a toggle at runtime.
varfeatureName="dashboard_widget";if(Features.Current.IsEnabled(featureName)){// New feature code hereShowDashboardWidget();}else{// Fallback or existing behaviorShowDefaultDashboard();}The toggle status is determined by:
- Storage Provider: Retrieves toggle configurations from your chosen storage medium
- Conditions: Evaluate criteria based on user claims, environment, time, or custom logic
- Operators: Combine multiple conditions using logical AND/OR operations
- Instant Rollback: Disable problematic features immediately without code deployment
- Gradual Rollout: Release features to small user groups first
- A/B Testing: Compare different implementations with real users
- Continuous Integration: Merge incomplete features safely using toggles
- Decoupled Deployments: Deploy code and activate features independently
- Environment-Specific Features: Show different features in different environments
- Faster Time-to-Market: Release features when business is ready, not just when code is ready
- User Segmentation: Target features to specific user groups
- Operational Control: Non-technical team members can control feature visibility
- Production Testing: Test features with real data and real users safely
- Canary Releases: Monitor feature performance with limited exposure
- Blue-Green Deployments: Switch between different feature sets instantly
- .NET Framework 4.6.2+ or .NET Core 2.1+ or .NET 5.0+
- Basic understanding of dependency injection (recommended)
// 1. Install the package// Install-Package FeatureOne.File// 2. Create a feature file (Features.json){"new_dashboard":{"toggle":{"conditions":[{"type":"simple","isEnabled": true
}]}}}// 3. Initialize FeatureOne (Traditional approach)varconfiguration=newFileConfiguration{FilePath=@"C:\path\to\Features.json"};varstorageProvider=newFileStorageProvider(configuration);Features.Initialize(()=>newFeatures(newFeatureStore(storageProvider)));// 4. Use in your codeif(Features.Current.IsEnabled("new_dashboard")){// Show new dashboard}A Feature represents a piece of functionality that can be toggled on or off. Each feature has:
- Name: Unique identifier for the feature
- Toggle: Configuration that determines when the feature is enabled
A Toggle contains the logic for determining feature enablement:
- Operator: How to combine multiple conditions (AND/OR)
- Conditions: Individual rules that evaluate to true/false
Conditions are the building blocks of toggle logic:
- SimpleCondition: Basic on/off switch
- RegexCondition: Evaluates user claims against regular expressions
- Custom Conditions: Implement
IConditionfor specific needs
Storage Providers retrieve feature configurations from various sources:
- FileStorageProvider: JSON files on disk
- SQLStorageProvider: SQL databases
- Custom Providers: Implement
IStorageProviderfor any data source
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Application │───▶│ Features │───▶│ FeatureStore │
│ │ │ (Entry Point) │ │ │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐
│ StorageProvider │
│ │
└─────────────────┘
│
┌──────────────────────┼──────────────────────┐
▼ ▼ ▼
┌──────────────┐ ┌──────────────────┐ ┌──────────────┐
│ FileProvider │ │ SQLProvider │ │CustomProvider│
└──────────────┘ └──────────────────┘ └──────────────┘
- Features: Main entry point for feature checking
- FeatureStore: Manages feature retrieval and caching
- StorageProvider: Abstracts data access
- Toggle: Contains evaluation logic
- Conditions: Individual evaluation rules
- Cache: Optional performance optimization
FeatureOne offers three NuGet packages based on your storage needs:
Install-Package FeatureOneUse when implementing custom storage providers.
Install-Package FeatureOne.SQLIncludes support for:
- Microsoft SQL Server
- SQLite
- MySQL
- PostgreSQL
- ODBC/OleDB sources
Install-Package FeatureOne.FileUses JSON files for feature storage.
// Configuration{"user_dashboard":{"toggle":{"conditions":[{"type":"simple","isEnabled": true
}]}}}// Usage
if (Features.Current.IsEnabled("user_dashboard")){returnView("NewDashboard");}returnView("OldDashboard");// Configuration{"admin_panel":{"toggle":{"conditions":[{"type":"regex","claim":"role","expression":"^administrator$"}]}}}// Usage
var claims =new Dictionary<string,string>{["role"]=user.Role,["email"]=user.Email};if(Features.Current.IsEnabled("admin_panel",claims)){ShowAdminPanel();}// Configuration - Feature enabled for admins OR beta users{"beta_feature":{"toggle":{"operator":"any","conditions":[{"type":"regex","claim":"role","expression":"^administrator$"},{"type":"regex","claim":"group","expression":"^beta_users$"}]}}}FeatureOne v5.1.0 introduces comprehensive dependency injection support for seamless integration with modern .NET applications.
// In Program.cs or Startup.csusingMicrosoft.Extensions.DependencyInjection;usingFeatureOne;publicvoidConfigureServices(IServiceCollectionservices){// Register FeatureOne with your storage provider using factory methodservices.AddFeatureOne(serviceProvider =>{// Create your storage provider implementation herevarstorageProvider=newYourStorageProviderImplementation();returnstorageProvider;});}// Register File Storage Provider with configurationservices.AddFeatureOneWithFileStorage(newFileConfiguration{FilePath="features.json",CacheSettings=newCacheSettings{EnableCache=true,Expiry=newExpiryPolicy{AbsoluteExpiration=TimeSpan.FromMinutes(5)}}});// Register SQL Storage Provider with configurationservices.AddFeatureOneWithSQLStorage(newSQLConfiguration{ConnectionSettings=newConnectionSettings{ConnectionString="Server=localhost;Database=FeatureToggles;Trusted_Connection=true;",ProviderName="System.Data.SqlClient"},CacheSettings=newCacheSettings{EnableCache=true,Expiry=newExpiryPolicy{AbsoluteExpiration=TimeSpan.FromMinutes(5)}}});// Register File Storage with custom componentsservices.AddFeatureOneWithFileStorage(configuration:newFileConfiguration{FilePath="features.json"},deserializer:newCustomToggleDeserializer(),// Optional: Pass null to use defaultcache:newCustomCache()// Optional: Pass null to use default);// Register SQL Storage with custom componentsservices.AddFeatureOneWithSQLStorage(configuration:newSQLConfiguration{ConnectionSettings=newConnectionSettings{ConnectionString="connection_string",ProviderName="System.Data.SqlClient"}},deserializer:newCustomToggleDeserializer(),// Optional: Pass null to use defaultcache:newCustomCache()// Optional: Pass null to use default);// Inject Features service directlypublicclassHomeController:Controller{privatereadonlyFeatures_features;publicHomeController(Featuresfeatures){_features=features;}publicIActionResultIndex(){if(_features.IsEnabled("new_dashboard")){returnView("NewDashboard");}returnView("OldDashboard");}}// Or inject in servicespublicclassUserService{privatereadonlyFeatures_features;publicUserService(Featuresfeatures){_features=features;}publicboolCanAccessPremiumFeatures(stringuserEmail){varclaims=newDictionary<string,string>{["email"]=userEmail};return_features.IsEnabled("premium_features",claims);}}All FeatureOne services are registered with Singleton lifetime to ensure:
- Consistent behavior across the application
- Optimal performance with caching
- Proper resource management
Here's a complete example showing how to integrate FeatureOne v5.1.0 with ASP.NET Core using dependency injection:
// Program.cs (ASP.NET Core 6+)usingMicrosoft.AspNetCore.Builder;usingMicrosoft.Extensions.DependencyInjection;usingMicrosoft.Extensions.Hosting;usingFeatureOne;usingFeatureOne.File.StorageProvider;varbuilder=WebApplication.CreateBuilder(args);// Add FeatureOne with File Storage Providerbuilder.Services.AddFeatureOneWithFileStorage(newFileConfiguration{FilePath="appsettings/features.json",CacheSettings=newCacheSettings{EnableCache=true,Expiry=newExpiryPolicy{AbsoluteExpiration=TimeSpan.FromMinutes(10)}}});// Add other servicesbuilder.Services.AddControllers();builder.Services.AddEndpointsApiExplorer();builder.Services.AddSwaggerGen();varapp=builder.Build();// Configure pipelineif(app.Environment.IsDevelopment()){app.UseSwagger();app.UseSwaggerUI();}app.UseHttpsRedirection();app.UseAuthorization();app.MapControllers();app.Run();// appsettings/features.json
{
"premium_features": {
"toggle": {
"operator": "any",
"conditions": [
{
"type": "Regex",
"claim": "subscription",
"expression": "^(premium|enterprise)$"
},
{
"type": "DateRange",
"startDate": "2025-10-01",
"endDate": "2025-12-31"
}
]
}
},
"admin_dashboard": {
"toggle": {
"conditions": [
{
"type": "Regex",
"claim": "role",
"expression": "^administrator$"
}
]
}
},
"beta_feature": {
"toggle": {
"conditions": [
{
"type": "Simple",
"isEnabled": true
}
]
}
}
}// Controllers/DashboardController.csusingMicrosoft.AspNetCore.Mvc;usingFeatureOne;[ApiController][Route("api/[controller]")]publicclassDashboardController:ControllerBase{privatereadonlyFeatures_features;publicDashboardController(Featuresfeatures){_features=features;}[HttpGet("overview")]publicIActionResultGetOverview(){varuserClaims=GetUserClaims();varviewModel=newDashboardViewModel{ShowPremiumWidgets=_features.IsEnabled("premium_features",userClaims),ShowAdminPanel=_features.IsEnabled("admin_dashboard",userClaims),ShowBetaFeatures=_features.IsEnabled("beta_feature",userClaims)};returnOk(viewModel);}privateDictionary<string,string>GetUserClaims(){returnnewDictionary<string,string>{["role"]=User?.Identity?.Name??"guest",["subscription"]=GetUserSubscription(),["userId"]=User?.Identity?.Name?.GetHashCode().ToString()??"anonymous"};}privatestringGetUserSubscription(){// In a real application, this would come from your auth systemreturn"premium";// Example value}}publicclassDashboardViewModel{publicboolShowPremiumWidgets{get;set;}publicboolShowAdminPanel{get;set;}publicboolShowBetaFeatures{get;set;}}This example demonstrates:
- ✅ Modern ASP.NET Core integration with top-level statements
- ✅ File-based feature storage with caching configuration
- ✅ Multiple condition types including the new DateRangeCondition
- ✅ Dependency injection of Features service into controllers
- ✅ Real-world feature configuration with complex conditions
- ✅ Proper service lifetime (Singleton) for optimal performance
Perfect for smaller applications or when feature configurations change infrequently.
- Create Feature File (
Features.json):
{
"feature_name": {
"toggle": {
"operator": "any",
"conditions": [
{
"type": "simple",
"isEnabled": true
}
]
}
}
}- Configure Provider:
varconfiguration=newFileConfiguration{FilePath=@"C:\path\to\Features.json",CacheSettings=newCacheSettings{EnableCache=true,Expiry=newCacheExpiry{InMinutes=60,Type=CacheExpiryType.Absolute}}};varstorageProvider=newFileStorageProvider(configuration);Features.Initialize(()=>newFeatures(newFeatureStore(storageProvider)));Ideal for enterprise applications requiring centralized feature management.
- Create Feature Table:
CREATETABLETFeatures (
Id INTNOT NULL IDENTITY PRIMARY KEY,
Name VARCHAR(255) NOT NULL,
Toggle NVARCHAR(4000) NOT NULL,
Archived BIT DEFAULT (0)
);- Insert Feature Data:
INSERT INTO TFeatures (Name, Toggle, Archived) VALUES (
'dashboard_widget',
'{ "conditions":[{ "type":"Simple", "isEnabled": true }] }',
0
);- Configure Provider:
// Register database providerDbProviderFactories.RegisterFactory("System.Data.SqlClient",SqlClientFactory.Instance);varsqlConfiguration=newSQLConfiguration{ConnectionSettings=newConnectionSettings{ProviderName="System.Data.SqlClient",ConnectionString="Data Source=server;Initial Catalog=Features;Integrated Security=SSPI;"},FeatureTable=newFeatureTable{TableName="TFeatures",NameColumn="Name",ToggleColumn="Toggle",ArchivedColumn="Archived"},CacheSettings=newCacheSettings{EnableCache=true,Expiry=newCacheExpiry{InMinutes=60}}};varstorageProvider=newSQLStorageProvider(sqlConfiguration);Features.Initialize(()=>newFeatures(newFeatureStore(storageProvider)));Implement IStorageProvider for integration with APIs, NoSQL databases, or other data sources:
publicclassApiStorageProvider:IStorageProvider{privatereadonlyHttpClienthttpClient;publicApiStorageProvider(HttpClienthttpClient){this.httpClient=httpClient;}publicIFeature[]GetByName(stringname){// Fetch from REST APIvarresponse=httpClient.GetAsync($"api/features/{name}").Result;varjson=response.Content.ReadAsStringAsync().Result;// Deserialize and return features// Implementation depends on your API structure}}Basic on/off switch, independent of user context.
{
"type": "simple",
"isEnabled": true
}newSimpleCondition{IsEnabled=true}Evaluates user claims against regular expressions.
{
"type": "regex",
"claim": "email",
"expression": "^[a-zA-Z0-9_.+-]+@company\\.com$"
}newRegexCondition{Claim="email",Expression=@"^[a-zA-Z0-9_.+-]+@company\.com$"}Email Domain Matching:
{
"claim": "email",
"expression": "@(company|partner)\\.com$"
}Role-Based Access:
{
"claim": "role",
"expression": "^(admin|moderator)$"
}User ID Ranges:
{
"claim": "userId",
"expression": "^[1-9][0-9]{3}$"
}Create custom conditions by implementing ICondition. FeatureOne v5.1.0 also includes a built-in DateRangeCondition for time-based feature toggles.
publicclassTimeBasedCondition:ICondition{publicintStartHour{get;set;}=9;publicintEndHour{get;set;}=17;publicboolEvaluate(IDictionary<string,string>claims){varcurrentHour=DateTime.Now.Hour;returncurrentHour>=StartHour&¤tHour<=EndHour;}}JSON Configuration:
{
"type": "TimeBased",
"startHour": 9,
"endHour": 17
}Usage:
// Business hours featureif(Features.Current.IsEnabled("business_hours_feature")){// Only available during business hours}Note: FeatureOne v5.1.0 includes a built-in
DateRangeConditionfor date-based feature toggles. See DateRangeCondition for more details.
Enable features based on date ranges with the new DateRangeCondition. Perfect for scheduled feature releases, temporary promotions, or trial periods.
{
"type": "DateRange",
"startDate": "2025-01-01",
"endDate": "2025-12-31"
}newDateRangeCondition{StartDate=newDateTime(2025,1,1),EndDate=newDateTime(2025,12,31)}Start Date Only (No end limit):
{
"type": "DateRange",
"startDate": "2025-06-01",
"endDate": null
}End Date Only (No start limit):
{
"type": "DateRange",
"startDate": null,
"endDate": "2025-08-31"
}Both Dates Null (Always enabled):
{
"type": "DateRange",
"startDate": null,
"endDate": null
}Seasonal Feature:
{
"holiday_promotion": {
"toggle": {
"conditions": [{
"type": "DateRange",
"startDate": "2025-11-01",
"endDate": "2025-12-31"
}]
}
}
}Beta Testing Period:
{
"beta_feature": {
"toggle": {
"conditions": [{
"type": "DateRange",
"startDate": "2025-10-01",
"endDate": "2025-12-31"
}]
}
}
}Usage in Code:
// Feature enabled during holiday seasonif(Features.Current.IsEnabled("holiday_promotion")){// Show special holiday offersShowHolidayPromotions();}// Feature enabled during beta testingif(Features.Current.IsEnabled("beta_feature")){// Show beta features to testersShowBetaFeatures();}Optimize performance with intelligent caching:
varcacheSettings=newCacheSettings{EnableCache=true,Expiry=newCacheExpiry{InMinutes=30,Type=CacheExpiryType.Sliding// Reset timer on access}};Cache Types:
- Absolute: Cache expires after fixed time
- Sliding: Cache expires after inactivity period
Monitor feature toggle behavior:
publicclassCustomLogger:IFeatureLogger{privatereadonlyILogger<CustomLogger>logger;publicCustomLogger(ILogger<CustomLogger>logger){this.logger=logger;}publicvoidInfo(stringmessage)=>logger.LogInformation(message);publicvoidDebug(stringmessage)=>logger.LogDebug(message);publicvoidWarn(stringmessage)=>logger.LogWarning(message);publicvoidError(stringmessage,Exceptionex)=>logger.LogError(ex,message);}// Register with FeatureOnevarcustomLogger=newCustomLogger(serviceProvider.GetService<ILogger<CustomLogger>>());Features.Initialize(()=>newFeatures(newFeatureStore(storageProvider,customLogger),customLogger));FeatureOne supports various database providers:
// SQL ServerDbProviderFactories.RegisterFactory("System.Data.SqlClient",SqlClientFactory.Instance);// MySQLDbProviderFactories.RegisterFactory("MySql.Data.MySqlClient",MySqlClientFactory.Instance);// PostgreSQLDbProviderFactories.RegisterFactory("Npgsql",NpgsqlFactory.Instance);// SQLiteDbProviderFactories.RegisterFactory("System.Data.SQLite",SQLiteFactory.Instance);publicclassPercentageRolloutCondition:ICondition{publicintPercentage{get;set;}publicboolEvaluate(IDictionary<string,string>claims){if(!claims.TryGetValue("userId",outstringuserIdStr))returnfalse;if(!int.TryParse(userIdStr,outintuserId))returnfalse;// Use user ID to determine consistent rolloutvarhash=userId.GetHashCode();varbucket=Math.Abs(hash%100);returnbucket<Percentage;}}Usage Example:
{
"new_checkout": {
"toggle": {
"conditions": [{
"type": "PercentageRollout",
"percentage": 25
}]
}
}
}publicclassRedisCacheProvider:ICache{privatereadonlyIConnectionMultiplexerredis;privatereadonlyIDatabasedatabase;publicRedisCacheProvider(IConnectionMultiplexerredis){this.redis=redis;this.database=redis.GetDatabase();}publicvoidAdd(stringkey,objectvalue,CacheItemPolicypolicy){varjson=JsonSerializer.Serialize(value);varexpiry=policy.AbsoluteExpiration.HasValue?policy.AbsoluteExpiration.Value.TimeOfDay:policy.SlidingExpiration;database.StringSet(key,json,expiry);}publicobjectGet(stringkey){varjson=database.StringGet(key);returnjson.HasValue?JsonSerializer.Deserialize<object>(json):null;}}For complex toggle requirements:
publicclassCustomToggleDeserializer:IToggleDeserializer{publicIToggleDeserialize(stringtoggle){// Custom deserialization logic// Handle special toggle formats// Support additional operators}}Good Names:
user_dashboard_v2
checkout_flow_redesign
mobile_payment_integration
Avoid:
feature1
test_toggle
temp_fix
publicclassFeatureToggleAudit{// Track toggle creation datepublicDateTimeCreatedDate{get;set;}// Review toggles older than 6 monthspublicboolRequiresReview=>DateTime.Now.Subtract(CreatedDate).Days>180;}Unit Testing:
[Test]publicvoidShould_Enable_Feature_For_Admin_Users(){// Arrangevarclaims=newDictionary<string,string>{["role"]="administrator"};// ActvarisEnabled=Features.Current.IsEnabled("admin_feature",claims);// AssertAssert.IsTrue(isEnabled);}Integration Testing:
[Test]publicvoidShould_Load_Features_From_Database(){// Test storage provider integration// Verify cache behavior// Test error handling}- Enable Caching: Always use caching for production
- Monitor Cache Hit Rates: Track cache effectiveness
- Optimize Database Queries: Index feature name columns
- Batch Feature Checks: Check multiple features in one call when possible
// Sanitize user inputspublicboolIsFeatureEnabledForUser(stringfeatureName,ClaimsPrincipaluser){// Validate feature nameif(string.IsNullOrWhiteSpace(featureName))returnfalse;// Extract only necessary claimsvarsafeClaims=ExtractSafeClaims(user);returnFeatures.Current.IsEnabled(featureName,safeClaims);}publicclassFeatureToggleMetrics{publicvoidRecordFeatureCheck(stringfeatureName,boolisEnabled,TimeSpanduration){// Log to metrics system// Alert on performance issues// Track feature usage}}Problem: Features.Current.IsEnabled() always returns false.
Solutions:
- Verify
Features.Initialize()was called - Check storage provider configuration
- Verify feature exists in storage
- Check condition syntax
Problem: SQL storage provider throws connection errors.
Solutions:
try{varfeatures=storageProvider.GetByName("test_feature");}catch(Exceptionex){logger.Error("Storage provider error",ex);// Handle gracefully - return default behavior}Problem: Changes to feature configurations not reflected immediately.
Solutions:
- Verify cache settings
- Check file change monitoring (for file provider)
- Consider cache invalidation strategy
Problem: Regex conditions not evaluating correctly.
Solutions:
- Test regex patterns separately
- Use online regex testing tools
- Check claim values are correct
- Verify case sensitivity
// Enable detailed loggingvarlogger=newCustomLogger();Features.Initialize(()=>newFeatures(newFeatureStore(storageProvider,logger),logger));// Test feature evaluationvartestClaims=newDictionary<string,string>{["email"]="test@company.com",["role"]="user"};varresult=Features.Current.IsEnabled("test_feature",testClaims);logger.Info($"Feature 'test_feature' evaluated to: {result}");publicclassPerformanceAwareFeatures{privatereadonlyStopwatchstopwatch=newStopwatch();publicboolIsEnabled(stringfeatureName,IDictionary<string,string>claims){stopwatch.Restart();varresult=Features.Current.IsEnabled(featureName,claims);stopwatch.Stop();if(stopwatch.ElapsedMilliseconds>100){logger.Warn($"Slow feature check: {featureName} took {stopwatch.ElapsedMilliseconds}ms");}returnresult;}}publicclassFeatures{publicstaticFeaturesCurrent{get;privateset;}// Initialize FeatureOnepublicstaticvoidInitialize(Func<Features>factory);// Check if feature is enabledpublicboolIsEnabled(stringname);publicboolIsEnabled(stringname,ClaimsPrincipalprincipal);publicboolIsEnabled(stringname,IEnumerable<Claim>claims);publicboolIsEnabled(stringname,IDictionary<string,string>claims);}publicinterfaceIStorageProvider{IFeature[]GetByName(stringname);}publicinterfaceICondition{boolEvaluate(IDictionary<string,string>claims);}// File StoragepublicclassFileConfiguration{publicstringFilePath{get;set;}publicCacheSettingsCacheSettings{get;set;}}// SQL StoragepublicclassSQLConfiguration{publicConnectionSettingsConnectionSettings{get;set;}publicFeatureTableFeatureTable{get;set;}publicCacheSettingsCacheSettings{get;set;}}// Cache SettingspublicclassCacheSettings{publicboolEnableCache{get;set;}publicCacheExpiryExpiry{get;set;}}// DateRangeCondition ⭐ NEW v5.1.0publicclassDateRangeCondition:ICondition{publicDateTime?StartDate{get;set;}publicDateTime?EndDate{get;set;}publicboolEvaluate(IDictionary<string,string>claims){varnow=DateTime.Now.Date;if(StartDate.HasValue&&now<StartDate.Value.Date)returnfalse;if(EndDate.HasValue&&now>EndDate.Value.Date)returnfalse;returntrue;}}- ICondition: Custom toggle conditions (includes built-in DateRangeCondition ⭐ NEW v5.1.0)
- IStorageProvider: Custom storage backends
- IFeatureLogger: Custom logging implementations
- ICache: Custom caching providers
- IConditionDeserializer: Custom condition deserialization
- IToggleDeserializer: Custom toggle deserialization
publicstaticclassFeatureOneServiceCollectionExtensions{publicstaticIServiceCollectionAddFeatureOne(thisIServiceCollectionservices,Func<IServiceProvider,IStorageProvider>storageProviderFactory);}publicstaticclassFeatureOneFileExtensions{publicstaticIServiceCollectionAddFeatureOneWithFileStorage(thisIServiceCollectionservices,FileConfigurationconfiguration,IToggleDeserializerdeserializer=null,ICachecache=null);}publicstaticclassFeatureOneSQLExtensions{publicstaticIServiceCollectionAddFeatureOneWithSQLStorage(thisIServiceCollectionservices,SQLConfigurationconfiguration,IToggleDeserializerdeserializer=null,ICachecache=null);}- RegexCondition ReDoS Protection: Added timeout validation to prevent Regular Expression Denial of Service attacks
- Secure Dynamic Type Loading: Replaced assembly scanning with explicit safe type registry to prevent unsafe type loading
- Actual Prefix Matching: Fixed FindStartsWith implementation to properly support prefix matching instead of exact matching
- Dependency Injection Patterns: Implemented proper dependency injection patterns with constructors that accept dependencies explicitly
- DateRangeCondition: Added new condition type for time-based feature toggles
- Configuration Validation: Added configuration validation system for feature names and condition parameters
- Core Service Registration: Added AddFeatureOne extension method for registering FeatureOne services with Microsoft.Extensions.DependencyInjection using factory pattern
- File Storage Provider Registration: Added AddFeatureOneWithFileStorage extension method for easy FileStorageProvider registration
- SQL Storage Provider Registration: Added AddFeatureOneWithSQLStorage extension method for easy SQLStorageProvider registration
- Comprehensive Test Coverage: Achieved 90%+ code coverage across all critical components
- Integration Testing: Complete end-to-end validation of all components
- External Condition Types: External condition types from other assemblies may no longer be loadable (security enhancement)
- Configuration Validation: May detect previously undetected configuration errors
Here's a comprehensive example showcasing all the new features in FeatureOne v5.1.0:
// Program.cs - Modern ASP.NET Core integration with DIusingMicrosoft.AspNetCore.Builder;usingMicrosoft.Extensions.DependencyInjection;usingMicrosoft.Extensions.Hosting;usingFeatureOne;usingFeatureOne.File.StorageProvider;varbuilder=WebApplication.CreateBuilder(args);// Register FeatureOne with comprehensive configurationbuilder.Services.AddFeatureOneWithFileStorage(newFileConfiguration{FilePath="app_data/features.json",CacheSettings=newCacheSettings{EnableCache=true,Expiry=newExpiryPolicy{AbsoluteExpiration=TimeSpan.FromMinutes(15),SlidingExpiration=TimeSpan.FromMinutes(5)}}});varapp=builder.Build();// API endpoint demonstrating all new v5.1.0 featuresapp.MapGet("/api/features",(Featuresfeatures,HttpContextcontext)=>{varuserClaims=newDictionary<string,string>{["role"]=context.User?.FindFirst("role")?.Value??"guest",["email"]=context.User?.FindFirst("email")?.Value??"",["subscription"]=GetUserSubscription(context),// premium, basic, trial, etc.["userId"]=context.User?.FindFirst("sub")?.Value??""};// Demonstrate all new v5.1.0 featuresvarfeatureStatus=new{// New DateRangeConditionseasonalPromotion=features.IsEnabled("seasonal_promotion",userClaims),// Security-enhanced RegexCondition with ReDoS protectionenterpriseEmail=features.IsEnabled("enterprise_email_access",userClaims),// Traditional simple togglenewDashboard=features.IsEnabled("new_dashboard",userClaims),// Complex toggle with multiple conditionspremiumFeatures=features.IsEnabled("premium_features",userClaims)};returnResults.Ok(featureStatus);});app.Run();stringGetUserSubscription(HttpContextcontext){// Implementation would check user's subscription statusreturn"premium";// Example}// app_data/features.json - Feature configuration showcasing v5.1.0 features
{
"seasonal_promotion": {
"description": "Holiday promotion active Dec 1-31",
"toggle": {
"conditions": [{
"type": "DateRange",
"startDate": "2025-12-01",
"endDate": "2025-12-31"
}]
}
},
"enterprise_email_access": {
"description": "Enterprise email domain access with ReDoS protection",
"toggle": {
"conditions": [{
"type": "Regex",
"claim": "email",
"expression": "^[a-zA-Z0-9._%+-]+@(enterprise|company)\\.com$"
}]
}
},
"premium_features": {
"description": "Premium subscription features with beta access",
"toggle": {
"operator": "any",
"conditions": [
{
"type": "Regex",
"claim": "subscription",
"expression": "^(premium|enterprise)$"
},
{
"type": "DateRange",
"startDate": "2025-11-01",
"endDate": "2025-12-31"
}
]
}
},
"new_dashboard": {
"description": "New dashboard UI",
"toggle": {
"conditions": [{
"type": "Simple",
"isEnabled": true
}]
}
}
}This showcase demonstrates:
- ✅ DateRangeCondition: Time-based feature toggles for seasonal promotions
- ✅ Enhanced Security: ReDoS protection in RegexCondition
- ✅ Modern DI Integration: Seamless ASP.NET Core integration
- ✅ Comprehensive Caching: Advanced cache configuration
- ✅ Real-world Scenarios: Practical feature toggle implementations
- ✅ Backward Compatibility: Works with existing simple toggles
FeatureOne provides a robust, flexible foundation for implementing feature toggles in .NET applications. Whether you're building a simple web application or a complex enterprise system, FeatureOne's extensible architecture adapts to your needs.
Key Takeaways:
- Start simple with basic toggles, then add complexity as needed
- Choose the right storage provider for your infrastructure
- Implement proper monitoring and logging
- Plan for toggle lifecycle management
- Test your feature toggle logic thoroughly
For additional help and community support, visit the GitHub repository or review the unit tests for comprehensive usage examples.
Happy feature toggling! 🚀
MIT License - Copyright (c) 2024 Ninja Sha!4h