This sample demonstrates how to use the OpenFeature .NET SDK in a console application. It includes a simple .NET 10 console app that defines several feature flags using the InMemoryProvider and evaluates them across all supported flag types: bool, int, string, double, and object.
The sample can easily be extended with alternative providers, which you can find in the dotnet-sdk-contrib repository.
- .NET 10 SDK installed on your machine.
-
Clone the repository:
git clone https://github.com/open-feature/dotnet-sdk.git openfeature-dotnet-sdk
-
Navigate to the Console sample project directory:
cd openfeature-dotnet-sdk/samples/Console -
Run the following command to start the application:
dotnet app.cs
The sample defines the following flags using the InMemoryProvider:
| Flag Key | Type | Variants | Default Variant |
|---|---|---|---|
bool-flag |
bool |
on → true, off → false |
on |
numeric-flag |
int |
one → 1, two → 2 |
one |
string-flag |
string |
greeting → "Hello, World!", farewell → "Goodbye, World!" |
greeting |
float-flag |
double |
pi → 3.14159, euler → 0.577215 |
pi |
object-flag |
object |
user1 → "Ralph", user2 → "Lewis" |
user2 |
This sample is published with NativeAOT enabled (PublishAot=true), demonstrating that the OpenFeature .NET SDK is fully compatible with NativeAOT compilation. See the AOT Compatibility Guide for more details.
The sample also demonstrates how to create an isolated API instance using Api.CreateIsolated(). The isolated instance has its own provider with different flag values, proving that it operates independently from the global singleton.
| Flag Key | Type | Variants | Default Variant |
|---|---|---|---|
bool-flag |
bool |
on → true, off → false |
off |
string-flag |
string |
greeting → "Howdy, Isolated World!", farewell → "See ya!" |
greeting |
The isolated instance evaluates flags from its own provider, then shuts down without affecting the global singleton. This is useful for testing, multi-tenant applications, and dependency injection scenarios. See the specification for more details.