C# / .NET SDK
GoGreen feature flag and experimentation SDK for .NET (C#). Evaluate flags, stream real-time updates, and track events. Supports .NET 8.0 and .NET Standard 2.0. Includes an OpenFeature provider.
Installation
From a project directory:
dotnet add package GoGreen.SdkOr add to your .csproj:
<PackageReference Include="GoGreen.Sdk" Version="1.0.0" />If the package is not yet published to NuGet, build from source:
cd sdk/dotnet/GoGreen.Sdk
dotnet pack -c Release
# Consume the .nupkg from bin/Release/Quick start
using GoGreen.Sdk;
// Build config with your SDK key and environment
var config = GoGreenConfig.CreateBuilder()
.WithSdkKey("your-sdk-key")
.WithEnvId("your-env-id")
.WithApiBaseUrl("https://app.gogreenflags.com")
.WithDefaultContext(EvaluationContext.CreateBuilder("user-123").Build())
.Build();
// Create client (async)
var client = await GoGreenClient.CreateAsync(config);
// Evaluate flags
bool enabled = await client.BoolVariationAsync("my-feature", false);
string plan = await client.StringVariationAsync("plan", "free");
double discount = await client.NumberVariationAsync("discount", 0.0);
// With detail (variation id, reason)
var detail = await client.BoolVariationDetailAsync("my-feature", false);
Console.WriteLine($"Value: {detail.Value}, Reason: {detail.Reason}");
// Change context
client.SetContext(EvaluationContext.CreateBuilder("other-user").SetCustom("country", "US").Build());
// Track custom events for experimentation
client.Track("purchase", new Dictionary<string, object?> { ["amount"] = 99.99 });
// Release resources
client.Close();Configuration
| Option | Description | Default |
|---|---|---|
SdkKey | SDK key for authentication | required |
EnvId | Environment identifier | required |
ApiBaseUrl | Evaluation API base URL | http://localhost:8092 |
StreamUrl | SSE stream URL | same as ApiBaseUrl |
EventsUrl | Events ingestion URL | same as ApiBaseUrl |
EnableStreaming | Real-time SSE updates | true |
Offline | Offline mode (cache/bootstrap only) | false |
RequestTimeoutMs | HTTP timeout (ms) | 10000 |
FlushIntervalMs | Event flush interval (ms) | 30000 |
DefaultContext | Default evaluation context | required |
Bootstrap | Pre-populated flags (e.g. for testing) | optional |
OpenFeature provider
using GoGreen.Sdk;
using GoGreen.Sdk.Provider;
using OpenFeature;
var client = await GoGreenClient.CreateAsync(config);
var provider = new GoGreenProvider(client);
await Api.Instance.SetProviderAsync(provider);
var featureClient = Api.Instance.GetClient();
bool value = await featureClient.GetBooleanValueAsync("my-flag", false);Testing
Use the test client for unit tests (no network, predefined flag values):
var flags = new Dictionary<string, object?>
{
["feature-on"] = true,
["plan"] = "pro"
};
var client = GoGreenClient.CreateTestClient(flags);
Assert.True(await client.BoolVariationAsync("feature-on", false));
Assert.Equal("pro", await client.StringVariationAsync("plan", "free"));
client.Close();API reference
- GoGreenClient:
CreateAsync,CreateTestClient,BoolVariationAsync,StringVariationAsync,NumberVariationAsync,JsonVariationAsync,*DetailAsyncvariants,SetContext,IdentifyAsync,Track,EnterOfflineMode,ExitOfflineModeAsync,Close,CloseAsync,WaitForInitialization - GoGreenConfig.Builder:
WithSdkKey,WithEnvId,WithApiBaseUrl,WithStreamUrl,WithEventsUrl,WithEnableStreaming,WithOffline,WithDefaultContext,WithBootstrap,Build - EvaluationContext:
CreateBuilder(key),Key,Custom - EvaluationDetail<T>:
Value,VariationId,VariationIndex,Reason,RuleIndex,PrerequisiteKey