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#)

A visual feature flag management service that enables remote control over the release of features to users.

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 here

Deploy to Azure with Terraform script
Check the Terraform script here

Deploy to Kubernetes with Helm Chart
Check the Helm Chart script here

Free 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

A feature toggle is a software development technique that enables turning a feature on or off at runtime. It is commonly used to hide, enable, or disable features while the application is running. This technique has various use cases across different c# applications, including:

Trunk based development

Many teams develop new features at a fast pace, and they deploy new features frequently. They merge the code frequently, and to avoid code merge conflicts and potential bugs, feature toggles are used to hide new features in a deployed application until they are ready to be released.

Decouple Release from Deploy

A new feature can be deployed on deployment day, but the business requirement may be to release the feature at a later date. Feature toggles can be used to decouple the deployment from the release, allowing the feature to be deployed and hidden until the release date.

Business Customization

To meet unique customer requirements, feature toggles are used to customize features. Although this method may introduce more if-else conditions in the codebase, it is much more efficient than creating hundreds of branches and multiple small component projects in the source code.

Permissioning and Entitlements

Feature toggles can control access to certain features based on user roles, subscription levels, or permissions, enabling a more granular control over who can use specific features of an application.

Feature Flag for .NET and C# applications

Implementing feature toggles in C# or .NET applications can't help mitigate the risk of deploying new features. Feature Flags were born, inheriting the concept of feature toggles and providing more powerful features to help developers mitigate the risks of deploying new features, such as Testing in Production, Canary Releases, Targeted Rollouts, A/B Testing, and more. All can be done remotely without redeploying the application.

Testing in Production

Feature flags allow you to test new features in production without redeploying and affecting all users. You can enable the feature for the QA team only by creating a reusable user segment and targeting the feature to that segment. Configuration updates are applied to applications.

Canary Release and Rollback Immediately

Feature flags allow you to gradually roll out features to a small percentage of users (or a targeted audience by condition), and then gradually increase the percentage. If something goes wrong, you can immediately roll back the feature without redeploying the application.

AB Testing

Feature Flags allows you to create multiple variations of a feature (instead of just true/false) and test them with different user segments. Using Bayesian statistics, you can measure the performance of each variation and decide which is best for your organization.

Entitlement Management

Feature flags can be used to control access to features based on user permissions. You can create a user segment based on user attributes (e.g., organizational ID, role, etc.) and target the feature to that segment. You can control the visibility of UI components, API endpoints, and so on.

Feature Flag for Asp.Net Core

Microsoft offers the Microsoft.FeatureManagement library to assist developers in implementing feature flags in ASP.NET Core applications. However, this library can only be managed remotely through Azure App Configuration and may not suit all feature flag scenarios. Consequently, FeatBit has introduced the FeatBit.ServerSdk to provide a more versatile solution for implementing feature flags in ASP.NET Core applications. Notably, Microsoft.FeatureManagement has greatly inspired the development of FeatBit.ServerSdk for ASP.NET Core applications.
ASP.NET enables developers to write a variety of backend applications, including web APIs, serverless functions, and web applications.

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

Companies increasingly use Blazor and WebAssembly for internal web apps, moving from Angular or React. FeatBit, responding to requests, you can combine FeatBit.ServerSdk and FeatBit.ClientSdk to implement Feature Flags in your Blazor applications.
For the case of server-side rendering, you can use FeatBit.ServerSdk to connect your Blazor Server application to the FeatBit Feature Flag server. Use dependency injection to inject the FeatBit.ServerSdk into your Blazor Server application. The feature flag is evaluated locally on the server side, then a rendered page is sent to the browser.

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.)

.NET (C#) is a very popular language for developing Windows applications, including WPF, WinForm, WinUI, and more. FeatBit offers the FeatBit.ClientSdk to connect your Windows applications to the FeatBit Feature Flag server.
The FeatBit.ClientSdk enables you to retrieve the latest feature flag evaluation results from the remote server for a specific user (or an anonymous user) and manage the code in your Windows application.

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

Many companies develop mobile applications using .NET MAUI (or Xamarin). FeatBit offers the FeatBit.ClientSdk to connect your .NET MAUI applications to the FeatBit server.
The FeatBit.ClientSdk enables you to retrieve the latest feature flag evaluation results from the remote server for a specific user (or an anonymous user) and manage the code in your .NET MAUI application.

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.

Feature Management for .NET and C# codebase.

Feature Management is more than a process of controlling and deploying features in software applications. It's more about how to manage features in a way that allows you to test and roll out features safely. It includes how to manage feature flags in a good organized way, how to use feature flags in your codebase, and how to handle feature flag.

Manage Features in a good organized way

A company may contain multiple projects and environments, and each project may include multiple features. Over time, these features accumulate, and many of them are controlled by feature flags. To manage the process of creating and maintaining a feature flag across projects and facilitating cooperation between teams, we need a user-friendly, well-organized system with robust access control.

Manage Feature Flags in Codebase

Proper management is crucial for feature flags in a codebase to avoid disorganization. This includes establishing naming conventions, providing implementation examples, defining lifecycle processes for various flag types, and removing outdated flags. Tools like Code References and IDE Plugins are essential for effective feature flag management , especially in .NET and C# codebases.