Skip to content

Latest commit

 

History

History
56 lines (36 loc) · 3.28 KB

File metadata and controls

56 lines (36 loc) · 3.28 KB

OpenFeature .NET Console Sample

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.

Prerequisites

Setup

  1. Clone the repository:

    git clone https://github.com/open-feature/dotnet-sdk.git openfeature-dotnet-sdk
  2. Navigate to the Console sample project directory:

    cd openfeature-dotnet-sdk/samples/Console
  3. Run the following command to start the application:

    dotnet app.cs

Feature Flags

The sample defines the following flags using the InMemoryProvider:

Flag Key Type Variants Default Variant
bool-flag bool ontrue, offfalse on
numeric-flag int one1, two2 one
string-flag string greeting"Hello, World!", farewell"Goodbye, World!" greeting
float-flag double pi3.14159, euler0.577215 pi
object-flag object user1"Ralph", user2"Lewis" user2

NativeAOT

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.

Isolated API Instance

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 ontrue, offfalse 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.