.NET SDK
Use Flipswitch with .NET via OpenFeature OFREP
Flipswitch works with .NET applications through the OpenFeature SDK and its native OFREP provider — no custom Flipswitch package needed.
GitHub: open-feature/dotnet-sdk · open-feature/dotnet-sdk-contrib
This integration uses the OpenFeature Remote Evaluation Protocol (OFREP), which evaluates flags via polling. Real-time SSE streaming is available in official Flipswitch SDKs.
Requirements
- .NET 8.0+
- OpenFeature SDK
Installation
dotnet add package OpenFeature.Providers.OfrepQuick Start
using OpenFeature;
using OpenFeature.Contrib.Providers.Ofrep;
var provider = new OFREPProvider(new OFREPProviderOptions
{
BaseUrl = "https://api.flipswitch.io",
Headers = new Dictionary<string, string>
{
["X-API-Key"] = "YOUR_API_KEY"
}
});
await Api.Instance.SetProviderAsync(provider);
var client = Api.Instance.GetClient();
var darkMode = await client.GetBooleanValueAsync("dark-mode", false);Evaluation Context
Pass user attributes for targeting:
var context = EvaluationContext.Builder()
.SetTargetingKey("user-123")
.Set("email", "user@example.com")
.Set("plan", "premium")
.Set("country", "SE")
.Build();
var showFeature = await client.GetBooleanValueAsync("new-feature", false, context);Detailed Evaluation
Get full evaluation details including variant and reason:
var details = await client.GetBooleanDetailsAsync("feature-flag", false, context);
Console.WriteLine($"Value: {details.Value}");
Console.WriteLine($"Variant: {details.Variant}");
Console.WriteLine($"Reason: {details.Reason}");ASP.NET Core Integration
var builder = WebApplication.CreateBuilder(args);
var provider = new OFREPProvider(new OFREPProviderOptions
{
BaseUrl = "https://api.flipswitch.io",
Headers = new Dictionary<string, string>
{
["X-API-Key"] = builder.Configuration["Flipswitch:ApiKey"]!
}
});
await Api.Instance.SetProviderAsync(provider);
var app = builder.Build();
app.MapGet("/feature", async (HttpContext http) =>
{
var client = Api.Instance.GetClient();
var context = EvaluationContext.Builder()
.SetTargetingKey(http.User.FindFirst("sub")?.Value ?? "anonymous")
.Build();
var enabled = await client.GetBooleanValueAsync("new-feature", false, context);
return Results.Ok(new { feature_enabled = enabled });
});
app.Run();Direct OFREP API
You can also call the OFREP endpoints directly via HTTP — see the OFREP protocol reference for details.