Binateq.FeatureManagement.Flipt
1.0.0
See the version list below for details.
dotnet add package Binateq.FeatureManagement.Flipt --version 1.0.0
NuGet\Install-Package Binateq.FeatureManagement.Flipt -Version 1.0.0
<PackageReference Include="Binateq.FeatureManagement.Flipt" Version="1.0.0" />
paket add Binateq.FeatureManagement.Flipt --version 1.0.0
#r "nuget: Binateq.FeatureManagement.Flipt, 1.0.0"
// Install Binateq.FeatureManagement.Flipt as a Cake Addin #addin nuget:?package=Binateq.FeatureManagement.Flipt&version=1.0.0 // Install Binateq.FeatureManagement.Flipt as a Cake Tool #tool nuget:?package=Binateq.FeatureManagement.Flipt&version=1.0.0
Binateq.FeatureManagement.Flipt
The NuGet package Binateq.FeatureManagement.Flipt allows to use the feature-flagging solution Flipt together with the Microsoft.FeatureManagement package.
What for?
The Microsoft.FeatureManagement provides simple and portable standard for .NET applications. It can be extended with feature filters, so you can use both static and dynamic feature flags.
You can add the packet Microsoft.Azure.AppConfiguration.AspNetCore to use dynamic feature flags configured in Microsoft Azure App Configuration service.
But what can you do, if you use Docker/Kubernetes instead of Azure? You can use any feature toggle solution like Flipt that has its own unique methods to work with feature flags.
Or you can use this package that implements feature filters' interface for Flipt gRPC API. In the latter case you can move your application from Azure to Docker and vice versa.
Quick Start
We'll use the standard ASP.NET Core template with Weather Forecast API to check feature flags.
Make the demo Web API application, as it described in the article above. Choose the type Web API and Windows Authentication.
Run it and check, if it works and accessible through the Swagger.
Classic Microsoft.FeatureManagement
Install the Microsoft.FeatureManagement packet:
dotnet add package Microsoft.FeatureManagement --version 2.6.1
Please note that you need to install the version 2.6.1 because something was broken in the 3.0.0..
We all are waiting for updates.
Include feature management support to configuration:
builder.Services.AddFeatureManagement(builder.Configuration.GetSection("FeatureFlags"));
Append new feature flag weather-forecast to the application.json configuration file:
{
"FeatureFlags": {
"weather-forecast": false
}
}
Append the _featureManager
to
WeatherForecastController
and initialize it through the constructor:
private readonly ILogger<WeatherForecastController> _logger;
private readonly IFeatureManager _featureManager;
public WeatherForecastController(ILogger<WeatherForecastController> logger, IFeatureManager featureManager)
{
_logger = logger;
_featureManager = featureManager;
}
Rewrite the Get
method to use the feature flag:
[HttpGet]
[Produces(typeof(IEnumerable<WeatherForecast>))]
public async Task<IActionResult> Get()
{
if (await _featureManager.IsEnabledAsync("weather-forecast"))
{
return Ok(Enumerable.Range(1, 5)
.Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
}));
}
return NotFound();
}
Run the application and call the Get
though the Swagger. It should return 404 status.
Then make file enabled (in the application.json) and re-run the application.
Call the Get
again. IT should return 200 status and the collection of forecast.
This static flag requires re-running of re-deploying of applications. Now let's try to use the dynamic flag.
Append dynamic flag from Flipt
Install and run Flipt Docker image:
docker run -d -p 8080:8080 -p 9000:9000 -v $HOME/flipt:/var/opt/flipt docker.flipt.io/flipt/flipt:latest
8080 is the port of Flipt Web UI and REST API, and 9000 is the port of gRPC API.
Open http://localhost:8080 after running. Enter the Flags panel and create Boolean flag with name Weather Forecast and key weather-forecast.
Install the package Binateq.FeatureManagement.Flipt:
dotnet add package Binateq.FeatureManagement.Flipt
Append FliptFeatureFilter
to composition root:
builder.Services.AddFeatureManagement(builder.Configuration.GetSection("FeatureFlags"))
.AddFeatureFilter<FliptFeatureFilter>();
Set gRPC API URL and FliptFeatureFilter
for the weather-forecast flag in the application.json:
{
"Flipt": {
"Url": "http://localhost:9080"
},
"FeatureFlags": {
"weather-forecast": {
"EnabledFor": [
{
"Name": "FliptFeature"
}
]
}
}
}
Please note that you need specify the filter FliptFeature
in the configuration, although the class is called
FliptFeatureFilter
.
Run the application and call the Get
though the Swagger. It should return 404 status.
Enable the flag weather-forecast in the Flipt Web UI and repeat the call.
The application should return 200 status and a list of forecasts.
Append user-specific flag form Flipt
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- Google.Protobuf (>= 3.25.1)
- Grpc.Net.Client (>= 2.59.0)
- Microsoft.FeatureManagement (>= 2.6.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.