This is the CloudBees provider implementation for OpenFeature for the dotnet SDK.
OpenFeature provides a vendor-agnostic abstraction layer on Feature Flag management.
This provider allows the use of CloudBees Feature Management as a backend for Feature Flag configurations.
- netframework 4.5.1 or greater
- .net core 3.1 or greater
Follow the instructions on the dotnet SDK project for how to use the dotnet SDK.
You can configure the CloudBees provider by doing the following:
Console app
using CloudBees.OpenFeature.Provider;
using OpenFeatureSDK = OpenFeature.SDK.OpenFeature;
CloudBeesProvider.Setup("API_KEY_GOES_HERE").Wait();
OpenFeatureSDK.Instance.SetProvider(new CloudBeesProvider());
var client = OpenFeatureSDK.Instance.GetClient();
var myCoolFlag = await client.GetBooleanValue("My_Cool_Flag", false);
AspNetCore app
// Add to service collection/DI setup
builder.Services.AddOpenFeatureCloudBees(options =>
{
options.ApiKey = builder.Configuration.GetValue<string>("CloudBeeApiKey");
});
// Add to class
public class WeatherForecastController : ControllerBase
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
private readonly FeatureClient _flagClient;
public WeatherForecastController(ILogger<WeatherForecastController> logger, FeatureClient flagClient)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_flagClient = flagClient ?? throw new ArgumentNullException(nameof(flagClient));
}
[HttpGet(Name = "GetWeatherForecast")]
public async Task<IEnumerable<WeatherForecast>> Get()
{
var showAsFahrenheit = await _flagClient.GetBooleanValue("ShowAsFahrenheit", false);
_logger.LogInformation("Evaluated ShowAsFahrenheit flag as {Value}", showAsFahrenheit);
return Enumerable.Range(1, 5).Select(index =>
{
var temperature = Random.Shared.Next(-20, 55);
return new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
Temperature = showAsFahrenheit ? 32 + (int)(temperature / 0.5556) : temperature,
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
};
})
.ToArray();
}
}
Thank you to Ben Evenson for the initial implementation