muench-develops.FeatureToggler
is a lightweight, extensible library for managing feature flags in .NET applications. It supports multiple providers (in-memory, JSON, environment variables, configuration) and integrates seamlessly with ASP.NET Core.
- Multiple Providers: In-Memory, JSON, Environment Variables, Configuration.
- ASP.NET Core Integration: Middleware and Dependency Injection support.
- Thread-Safe: Concurrent updates handled efficiently.
- Testable: Clean design for easy unit testing.
- Extensible: Add custom providers effortlessly.
Install FeatureToggler via NuGet:
dotnet add package muench-develops.FeatureToggler
Add providers in your Program.cs or Startup.cs:
builder.Services.AddFeatureFlags(
new InMemoryFeatureFlagProvider(
new[]
{
new FeatureFlag("EnableNewUI", true, "Enables the new UI"),
new FeatureFlag("BetaFeature", false, "Beta feature toggle")
})
);
Execute actions based on feature flag states:
app.UseFeatureFlag("EnableNewUI",
onEnabled: () => Console.WriteLine("New UI is enabled!"),
onDisabled: () => Console.WriteLine("New UI is disabled!"));
app.MapGet("/", (FeatureFlagManager manager) => manager.IsEnabled("EnableNewUI")
? Results.Ok("Welcome to the new UI!")
: Results.Ok("Welcome to the old UI!"));
Check or update feature flags dynamically:
var manager = app.Services.GetRequiredService<FeatureFlagManager>();
if (manager.IsEnabled("EnableNewUI"))
{
Console.WriteLine("New UI is enabled!");
}
- In-Memory: Simple and fast for development.
- JSON: Load feature flags from a JSON file.
- Environment Variables: Configure flags via environment variables.
We welcome contributions! Please fork the repository and submit a pull request with your changes. For major updates, open an issue first to discuss your ideas.
This project is licensed under the Apache License. See the LICENSE file for details.