C# SDK 2.1.0 adds GrowthBookClient, which loads features once and evaluates them for a user you pass with each call. One instance can serve many users, and you can register it as a singleton with dependency injection.
One client for many users
The SDK's GrowthBookFactory creates one GrowthBook instance per user. GrowthBookFactory is now marked obsolete in favor of GrowthBookClient.
- You build a
UserContextfor the user being evaluated and pass it with the call.UserContextis now public. - The client's options hold your SDK connection's client key, an API host that defaults to
https://cdn.growthbook.io, and an optional decryption key for encrypted payloads. - The existing
IGrowthBookinterface does not change.GrowthBookClientis a new type alongside it.
Registration and the first load
AddGrowthBookClientregisters the client as a singleton and loads features before its first use.- A response with no
featurespayload counts as a failed load, not an empty one. - Set
ThrowOnInitializationFailureif a failed initial load should stop the client from resolving. The registration then disposes the client and rethrows. - The package now depends on
Microsoft.Extensions.DependencyInjection.Abstractions.
Safer typed reads
In the existing GrowthBook class, GetFeatureValue and GetFeatureValueAsync now return your fallback when a value can't be converted to the requested type. Reading "off" as a bool used to throw a FormatException. When a logger is configured, the SDK also logs a warning.
Getting started
Install or upgrade the package with dotnet add package growthbook-c-sharp --version 2.1.0. Then call AddGrowthBookClient in your service registration, or construct GrowthBookClient with options that include your client key. Pass a UserContext with each evaluation.
The C# SDK documentation covers installation and the existing GrowthBook class. Log in to GrowthBook to copy the client key from the SDK connection your application uses.