GrowthBook.OpenFeature
0.0.1
dotnet add package GrowthBook.OpenFeature --version 0.0.1
NuGet\Install-Package GrowthBook.OpenFeature -Version 0.0.1
<PackageReference Include="GrowthBook.OpenFeature" Version="0.0.1" />
<PackageVersion Include="GrowthBook.OpenFeature" Version="0.0.1" />
<PackageReference Include="GrowthBook.OpenFeature" />
paket add GrowthBook.OpenFeature --version 0.0.1
#r "nuget: GrowthBook.OpenFeature, 0.0.1"
#addin nuget:?package=GrowthBook.OpenFeature&version=0.0.1
#tool nuget:?package=GrowthBook.OpenFeature&version=0.0.1
GrowthBook OpenFeature Provider for .NET
This is the official GrowthBook provider for the OpenFeature .NET SDK. It allows you to leverage GrowthBook as your feature flag system through the standardized OpenFeature API.
Quick Start
- Install the package
- Create a GrowthBook provider
- Register with OpenFeature
- Start evaluating feature flags
Requirements
- .NET 8+
- .NET Standard 2.0+ (.NET Framework 4.6.1+, .NET Core 2.0+)
Installation
dotnet add package GrowthBook.OpenFeature
Basic Usage
using GrowthBook.OpenFeature;
using OpenFeature;
using OpenFeature.Model;
// Initialize the GrowthBook provider
var provider = new GrowthBookProvider(
clientKey: "sdk-abc123",
apiHostUrl: "https://cdn.growthbook.io"
);
// Register the provider with OpenFeature
Api.Instance.SetProvider(provider);
// Create an evaluation context with targeting information
var context = new EvaluationContext(
targetingKey: "user-123",
new Dictionary<string, Value>
{
{ "email", new Value("user@example.com") },
{ "country", new Value("USA") },
{ "premium", new Value(true) }
}
);
// Get the client
var client = Api.Instance.GetClient();
// Evaluate a feature flag
bool isEnabled = await client.GetBooleanValue("new-dashboard", false, context);
// Use the feature flag in your application logic
if (isEnabled)
{
// Show the new dashboard
}
else
{
// Show the old dashboard
}
Available Flag Types
This provider supports all OpenFeature evaluation types:
// Boolean flags
bool enabled = await client.GetBooleanValue("feature-enabled", false, context);
// String flags
string variant = await client.GetStringValue("button-color", "blue", context);
// Integer flags
int limit = await client.GetIntegerValue("api-request-limit", 100, context);
// Double flags
double price = await client.GetDoubleValue("subscription-price", 9.99, context);
// Object flags
Value config = await client.GetObjectValue("feature-config", new Value(new Dictionary<string, Value>()), context);
Advanced Usage
Using an Existing GrowthBook Instance
If you already have a GrowthBook instance configured:
// Create GrowthBook context
var gbContext = new GrowthBook.Context
{
ApiHost = "https://cdn.growthbook.io",
ClientKey = "sdk-abc123",
Enabled = true,
// Add additional configuration as needed
};
// Create and configure a GrowthBook instance
var growthBook = new GrowthBook.GrowthBook(gbContext);
// Initialize the GrowthBook provider with the existing instance
var provider = new GrowthBookProvider(growthBook);
// Register the provider with OpenFeature
Api.Instance.SetProvider(provider);
Handling Context Changes
You can update the evaluation context at any time:
// Create new context when user logs in
var userContext = new EvaluationContext(
targetingKey: "user-456",
new Dictionary<string, Value>
{
{ "email", new Value("new-user@example.com") },
{ "subscriptionTier", new Value("premium") }
}
);
// Update the client with the new context
client.SetEvaluationContext(userContext);
// All subsequent evaluations will use the new context
var result = await client.GetBooleanValue("premium-feature", false);
Project Structure
The solution consists of:
- GrowthBook.OpenFeature: The main library implementing the OpenFeature provider
- GrowthBook.OpenFeature.Tests: Unit tests for the provider
Troubleshooting
Common Issues
- Feature flag not found: Ensure your
clientKey
is correct and that the flag exists in your GrowthBook project - Incorrect targeting: Check that your evaluation context contains the expected targeting attributes
- No connection to GrowthBook: Verify your
apiHostUrl
is correct and network connectivity is available
Debugging
Enable verbose logging to see detailed evaluation information:
OpenFeature.Api.Instance.SetLoggerFactory(new ConsoleLoggerFactory(LogLevel.Debug));
Contributing
Contributions are welcome! See CONTRIBUTING.md for details.
License
MIT
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- growthbook-c-sharp (>= 1.1.0)
- Microsoft.Bcl.AsyncInterfaces (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
- OpenFeature (>= 2.4.0)
- System.Threading.Tasks.Extensions (>= 4.5.4)
-
net8.0
- growthbook-c-sharp (>= 1.1.0)
- Newtonsoft.Json (>= 13.0.3)
- OpenFeature (>= 2.4.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.0.1 | 169 | 4/22/2025 |