Skip to main content
Version: Config V1 (legacy)

OpenFeature Provider for .NET

ConfigCat OpenFeature Provider for .NET on GitHub

Getting started

1. Install the provider

Install-Package OpenFeature.Contrib.Providers.ConfigCat

2. Initialize the provider

The ConfigCatProvider constructor takes the SDK key and an optional ConfigCatClientOptions argument containing the additional configuration options for the ConfigCat .NET SDK:

using OpenFeature.Contrib.Providers.ConfigCat;

// Build options for the ConfigCat SDK.
var options = new ConfigCatClientOptions
{
PollingMode = PollingModes.AutoPoll(pollInterval: TimeSpan.FromSeconds(60));
Logger = new ConsoleLogger(LogLevel.Warning);
// ...
};

// Configure the provider.
OpenFeature.Api.Instance.SetProvider(new ConfigCatProvider("#YOUR-SDK-KEY#", options));

// Create a client.
var client = OpenFeature.Api.Instance.GetClient();

For more information about all the configuration options, see the .NET SDK documentation.

3. Evaluate your feature flag

var isAwesomeFeatureEnabled = await client.GetBooleanValueAsync("isAwesomeFeatureEnabled", false);
if(isAwesomeFeatureEnabled)
{
doTheNewThing();
}
else
{
doTheOldThing();
}

Evaluation Context

An evaluation context in the OpenFeature specification is a container for arbitrary contextual data that can be used as a basis for feature flag evaluation. The ConfigCat provider translates these evaluation contexts to ConfigCat User Objects.

The following table shows how the different context attributes are mapped to User Object attributes.

Evaluation contextUser ObjectRequired
Id/IdentifierIdentifier
EmailEmail
CountryCountry
Any otherCustom

To evaluate feature flags for a context, use the OpenFeature Evaluation API:

var context = new EvaluationContext()
.Set("Id", "#SOME-USER-ID#")
.Set("Email", "[email protected]")
.Set("Country", "CountryID")
.Set("Rating", 4.5)
.Set("RegisteredAt", DateTime.Parse("2023-11-22 12:34:56 +00:00", CultureInfo.InvariantCulture))
.Build();

var isAwesomeFeatureEnabled = await client.GetBooleanValueAsync("isAwesomeFeatureEnabled", false, context);

Look under the hood