Skip to main content

Installation

Requirements: .NET 8+, ASP.NET Core (for the hosted service integration)

Setup

Register OmniFlags in Program.cs. The SDK key is the only thing you configure locally. Polling intervals and CDN settings come down with the snapshot.
Store the SDK key in appsettings.json. Use environment-specific overrides (appsettings.Production.json) or secret management to keep production keys out of source control.
AddOmniFlags registers:
  • OmniFlagsClient as a singleton in the DI container
  • A hosted service that fetches the initial snapshot at startup, before the application begins accepting traffic
By the time the first request arrives, the flag snapshot is loaded and OmniFlagsClient is ready to evaluate.

Evaluating flags

Inject OmniFlagsClient 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

Returns the flag value as a 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 an EvaluationContext 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").
Rollout and traffic splits require a bucketing key (CustomerId, AgentId, etc.) to produce a deterministic result. If no bucketing key is present, the SDK returns the flag’s default value with ErrorCode.MissingTargetingKey.

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.
Background polling continues throughout the application’s lifetime. The polling interval is set server-side and delivered in the snapshot.

Shutdown

OmniFlagsClient implements IAsyncDisposable. The DI container disposes the singleton as part of the host shutdown sequence. No manual teardown is required.