Installation
Setup
Register OmniFlags inProgram.cs. The SDK key is the only thing you configure locally. Polling intervals and CDN settings come down with the snapshot.
appsettings.json. Use environment-specific overrides (appsettings.Production.json) or secret management to keep production keys out of source control.
AddOmniFlags registers:
OmniFlagsClientas a singleton in the DI container- A hosted service that fetches the initial snapshot at startup, before the application begins accepting traffic
OmniFlagsClient is ready to evaluate.
Evaluating flags
InjectOmniFlagsClient into services, controllers, or minimal API endpoints. The client is thread-safe and designed to be shared as a singleton.
In a service class
In a minimal API endpoint
Client API
IsEnabled — boolean flags
bool. The defaultValue is returned if the flag is not found, is disabled, or the client is not yet ready.
GetString — string flags
GetNumber — number flags
Detail variants
Every typed method has a*Detail variant that returns the full EvaluationResult<T>. Use it when you need to inspect why a value was returned; useful for logging, analytics, or debugging evaluation logic.
Evaluation context
Construct anEvaluationContext with the user and session attributes available at the call site. All properties are optional. Include only what’s relevant to your targeting rules.
Additional key-value pairs set on the context dictionary are available for custom attribute matching in targeting rules, including dot-path traversal (e.g.,
ctx["user.plan"] = "enterprise").
Startup behaviour
AddOmniFlags registers a hosted service that fetches the initial snapshot during IHostedService.StartAsync, before the application begins serving traffic. This means:
- Flags are always ready on the first request. No warm-up period, no stale defaults on startup.
- Startup failure does not block the application. If the CDN is unreachable at startup, the hosted service logs the error and the client falls back to an empty snapshot. The application starts, and evaluation returns caller-supplied defaults until the next successful poll.
Shutdown
OmniFlagsClient implements IAsyncDisposable. The DI container disposes the singleton as part of the host shutdown sequence. No manual teardown is required.