Feature Flag Service for .NET and C# Applications
Feature Flag Service for .NET and C# Applications
FeatBit, an open-source feature flags management service built with .NET (C#). It offers comprehensive SDKs for various platforms including ASP.NET Core, Console Apps, MAUI, WPF, and Blazor WebAssembly, among others. These SDKs are also compatible with netstandard2.0 and netstandard2.1, supporting a wide range of C# and .NET applications.

Getting Started with Feature Flag for .NET (C#)

Install Feature Flag Service
A visual feature flag management service that enables remote control over the release of features to users.
The core modules are built with .NET 6+ : 1. The APIs service serves for the management and configuration of feature flags. ; 2. The evaluation service serves for the remote control of the release of features to users.
You can install FeatBit easily with Docker, Kubernetes, Azure and so on.
Docker Compose
Check the documentation hereDeploy to Azure with Terraform script
Check the Terraform script hereDeploy to Kubernetes with Helm Chart
Check the Helm Chart script hereFree Trial FeatBit's Hosting Service

.NET SDKs
FeatBit's Feature Flag .NET SDKs designed to connect your .NET applications to the FeatBit Feature Flag Server,
SDKs allow for easy integration of feature flags into .NET applications, ensuring stability, reliability, and performance without concerns like memory leaks or thread safety.
The SDKs are compatible with .NET Standard 2.0 and .NET Standard 2.1, .NET Core 3.1 and higher.
.NET SDK built for backend applications
FeatBit.ServerSdk is built for backend applications such as ASP.NET Core, ASP.NET Blazor SSR, Serveless Functions, Console Apps, and more. Getting Started with FeatBit.ServerSdk's GitHub.
.NET SDK built for client applications
FeatBit.ClientSdk is built for client applications such as ASP.NET Blazor WebAssembly, WPF, MAUI, and more. Getting Started with FeatBit.ClientSdk's GitHub.
C# Feature Toggle

Trunk based development
Decouple Release from Deploy
Business Customization
Permissioning and Entitlements
Feature Flag for .NET and C# applications

Testing in Production
Canary Release and Rollback Immediately
AB Testing
Entitlement Management
Feature Flag for Asp.Net Core
FeatBit offers the FeatBit.ServerSdk to connect your ASP.NET Core applications to the FeatBit Feature Flag server. The FeatBit.ServerSdk synchronizes the feature flag configuration between the application and the remote FeatBit server and evaluates the feature flag locally on the server side to avoid network latency issues.
Furthermore, the FeatBit.ServerSdk is designed to be thread-safe, free from memory leaks, and high-performing, among other benefits.
You can use Dependency Injection to inject the FeatBit.ServerSdk into your ASP.NET Core application and use the feature flag in your codebase.
# Add FeatBit service in Program.cs file in ASP.NET Core
using FeatBit.Sdk.Server.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
// add FeatBit service
builder.Services.AddFeatBit(options =>
{
options.EnvSecret = "<replace-with-your-env-secret>";
options.StreamingUri = new Uri("ws://localhost:5100");
options.EventUri = new Uri("http://localhost:5100");
options.StartWaitTime = TimeSpan.FromSeconds(3);
});
var app = builder.Build();
app.Run();
# Inject FeatBit service in Controller
public class HomeController : ControllerBase
{
private readonly IFbClient _fbClient;
public HomeController(IFbClient fbClient)
{
_fbClient = fbClient;
}
[HttpGet]
public IActionResult Index()
{
# Use FeatBit service to evaluate feature flag
HttpContext.Request.Headers.TryGetValue("X-FeatBit-User-Key", out var userKey);
HttpContext.Request.Headers.TryGetValue("X-FeatBit-User-Name", out var userName);
var user = FbUser.Builder(userKey)
.Name(userName)
.Build();
if (_fbClient.BoolVariation("welcome-sentence", user, defaultValue: false))
{
return Ok("Welcome to our website!");
}
return NotFound();
}
}
Feature Flag for Blazor and Blazor WebAssembly
In the case of client-side rendering, you need to use FeatBit.ClientSdk to retrieve the latest feature flag evaluation result from the remote server of a specific user (or an anonymous user). It's a different approach than server-side rendering, the code is executed on the browser, and the feature flag controls the code in the browser.
Technically, two rendering modes require different SDKs, and they run separately. But for the feeling, they are the same, once you update the feature flag configuration on the FeatBit's portal, the feature flag evaluation result will be updated in (can be real-time) on the client-side and server-side.
### Server Side Rendering ###
# Initialize server-side SDK in Program.cs file in Blazor Server
builder.Services.AddFeatBit(options =>
{
options.EnvSecret = "{Environment_Server_Key}";
options.StreamingUri = new Uri("wss://{EVALUATION_SERVER_URL}");
options.EventUri = new Uri("https://{EVALUATION_SERVER_URL}");
options.StartWaitTime = TimeSpan.FromSeconds(3);
});
# Create a FeatureFlag component in Blazor Server
@using FeatBit.Sdk.Server
@using FeatBit.Sdk.Server.Model
@inject IFbClient FeatureFlags
@if (FeatureFlags.FeatureReleased(FlagKey) == true)
{
@ChildContent
}
@code {
[Parameter]
public RenderFragment? ChildContent { get; set; }
[Parameter]
public string FlagKey { get; set; }
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
}
}
# Use component below to wrap the feature code
@inject IFbClient FeatureFlags
<FeatureFlag FlagKey="welcom-sentence">
<h5>
Welcome to our website!
We're thrilled to have you here and can't
wait to share our journey with you.
</h5>
</FeatureFlag>
### Client Side Rendering ###
# Initialize client-side SDK in MainLayout.razor
# file in Blazor WebAssembly
protected override async Task OnInitializedAsync()
{
var options = new FbOptionsBuilder("{Environment_Client_Key}")
.Eval(new Uri("https://{EVALUATION_SERVER_URL}"))
.PollingInterval(5000)
.LoggerFactory(LoggerFactory)
.Build();
FeatureFlagStore = new FbClient(options);
FeatureFlagStore.FeatureFlagsUpdated += (sender, e) =>
{
InvokeAsync(() =>
{
RenderMessage = FeatureFlagStore.StringVariation(
"testing-visibility", "Collapsed");
StateHasChanged(); // Rerender the component
}).Wait();
};
}
# Use CascadingParameter to pass the Feature Flag
# to the child component
[CascadingParameter]
public FbClient FeatureFlagStore { get; set; }
protected override async Task OnInitializedAsync()
{
FeatureFlagStore.FeatureFlagsUpdated += (sender, e) =>
{
InvokeAsync(() =>
{
renderMessage = FeatureFlagStore.StringVariation(
"testing-visibility", "Collapsed");
StateHasChanged(); // Rerender the component
}).Wait();
};
renderMessage = FeatureFlagStore.StringVariation(
"testing-visibility", "Collapsed");
StateHasChanged();
}
Feature Flag for Windows Applications (WPF, WinForm, WinUI, etc.)
Unlike the backend SDK, the client-side SDK relies on the server to evaluate flags, whereas the server-side SDK performs the evaluation locally. The FeatBit.ClientSdk is intended for individual users.
Despite being designed to be lightweight, the FeatBit.ClientSdk maintains thread safety, is free from memory leaks, and delivers high performance, among other advantages.
Depending on your architecture, you can use Dependency Injection to integrate the FeatBit.ClientSdk into your Windows application. You can employ callbacks to listen for feature flag updates and refresh the UI accordingly. The feature flags are compatible with both MVVM and MVC design patterns.
# Initialize client-side SDK in App.xaml.cs file in WPF
var options = new FbOptionsBuilder("{Environment_Client_Key}")
.Eval(new Uri("{EVALUATION_SERVER_URL}"))
.LoggerFactory(consoleLoggerFactory)
.PollingInterval(10000)
.Build();
services.AddSingleton<IFbClient>(provider => new FbClient(options));
# Login user and identify user in WPF
var user = FbUser.Builder("{user_id}")
.Name("{user_name}")
.Custom("{user_custom_property_1", "{value_1}")
.Custom("{user_custom_property_2", "{value_2}")
.Build();
await _fbClient.IdentifyAsync(user);
# Inject FeatBit service in View
private readonly IFbClient _fbClient;
public MainWindow(
IFbClient fbClient,
MainViewModel viewModel)
{
InitializeComponent();
_fbClient = fbClient;
Loaded += MainWindow_Loaded;
Unloaded += (s, e) =>
{
_fbClient.FeatureFlagsUpdated -= FeatureFlagsUpdated;
};
}
# Monitor feature flag changes
private void FeatureFlagsUpdated(object? sender, FeatureFlagsUpdatedEventArgs e)
{
Dispatcher.BeginInvoke(new System.Action(() =>
{
SetVisibility();
}));
}
# Use fbClient to evaluate feature flag
private void SetVisibility()
{
var visibleStatus = _fbClient.StringVariation("testing-visibility", "Collapsed");
switch (visibleStatus)
{
case "Visible":
TextBox_Thanks.Visibility = Visibility.Visible;
break;
case "Collapsed":
TextBox_Thanks.Visibility = Visibility.Collapsed;
break;
default:
TextBox_Thanks.Visibility = Visibility.Hidden;
break;
}
double numb = _fbClient.DoubleVariation("float-func", 0);
}
Feature Flag for .NET MAUI
The usage of FeatBit.ClientSdk in .NET MAUI is similar to that in Blazor WebAssembly and windows applications. You can use Dependency Injection to inject the FeatBit.ClientSdk into your .NET MAUI application and use the feature flag in your codebase.
The mobile application's network isn't always stable, so the FeatBit.ClientSdk provides several methods that developers can use to ensure the feature flag evaluation result is up-to-date.
A polling mechanism is used to check the latest feature flag evaluation result from the remote server. A mannual refresh mechanism is also provided to allow developers to refresh the feature flag evaluation result when needed.
# Initialize client-side SDK in .NET MAUI
var consoleLoggerFactory = LoggerFactory.Create(builder =>
{
builder.AddConsole();
});
var options = new FbOptionsBuilder("{Environment_Client_Key}")
.Eval(new Uri("{EVALUATION_SERVER_URL}"))
.LoggerFactory(consoleLoggerFactory)
.PollingInterval(5000)
.Build();
builder.Services.AddSingleton<IFbClient>(provider =>
new FbClient(options, autoSync: true));
# Inject FeatBit service in ViewModel
private readonly IFbClient _fbClient;
public MyFavoritesViewModel(
ISportsService sportsService,
IFbClient fbClient)
{
_sportsService = sportsService;
_fbClient = fbClient;
}
# Use SDK to evaluate feature flag
MyFavoriteGynasmesVisibility = (_fbClient.StringVariation("testing-visibility", "Collapsed") == "Visible");
# For other usage, it's as same as WPF, WinForm, Blazor, etc.