-
Notifications
You must be signed in to change notification settings - Fork 25
docs: Add .NET 10 Console sample application #722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
askpt
merged 4 commits into
open-feature:main
from
kylejuliandev:kylej/add-console-sample-app
Mar 27, 2026
+98
−3
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
14bfb6b
Add .NET 10 Console sample application
kylejuliandev f2ee9a6
Address Gemini code review comments
kylejuliandev e800363
Convert Console app to single file app
kylejuliandev ab2c981
Merge branch 'main' into kylej/add-console-sample-app
kylejuliandev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| using OpenFeature; | ||
| using OpenFeature.Model; | ||
| using OpenFeature.Providers.Memory; | ||
|
|
||
| var flags = new Dictionary<string, Flag> | ||
| { | ||
| { "bool-flag-flag", new Flag<bool>(new Dictionary<string, bool> { { "on", true }, { "off", false } }, defaultVariant: "on") }, | ||
| { "numeric-flag", new Flag<int>(new Dictionary<string, int> { { "one", 1 }, { "two", 2 } }, defaultVariant: "one") }, | ||
| { "string-flag", new Flag<string>(new Dictionary<string, string> { { "greeting", "Hello, World!" }, { "farewell", "Goodbye, World!" } }, defaultVariant: "greeting") }, | ||
| { "float-flag", new Flag<double>(new Dictionary<string, double> { { "pi", 3.14159 }, { "euler", 0.577215 } }, defaultVariant: "pi") }, | ||
| { "object-flag", new Flag<Value>(new Dictionary<string, Value> { { "user1", new Value("Ralph") }, { "user2", new Value("Lewis") } }, defaultVariant: "user2" ) } | ||
| }; | ||
|
|
||
| await Api.Instance.SetProviderAsync(new InMemoryProvider(flags)); | ||
|
|
||
| IFeatureClient client = Api.Instance.GetClient(); | ||
|
|
||
| // Evaluate the `bool-flag` flag and print the result to the console | ||
| var helloWorldResult = await client.GetBooleanValueAsync("bool-flag", false); | ||
| if (helloWorldResult) | ||
| { | ||
| Console.WriteLine("The `bool-flag` flag was enabled!"); | ||
| } | ||
| else | ||
| { | ||
| Console.WriteLine("The `bool-flag` flag was disabled!"); | ||
| } | ||
|
|
||
| // Evaluate the `numeric-flag` flag and print the result to the console | ||
| var numericResult = await client.GetIntegerValueAsync("numeric-flag", 0); | ||
| Console.WriteLine("The `numeric-flag` flag returned {0}", numericResult); | ||
|
|
||
| // Evaluate the `string-flag` flag and print the result to the console | ||
| var stringResult = await client.GetStringValueAsync("string-flag", "default"); | ||
| Console.WriteLine("The `string-flag` flag returned {0}", stringResult); | ||
|
|
||
| // Evaluate the `float-flag` flag and print the result to the console | ||
| var floatResult = await client.GetDoubleValueAsync("float-flag", 0.0); | ||
| Console.WriteLine("The `float-flag` flag returned {0}", floatResult); | ||
|
|
||
| // Evaluate the `object-flag` flag and print the result to the console | ||
| var objectResult = await client.GetObjectValueAsync("object-flag", new Value("Ben")); | ||
| Console.WriteLine("The `object-flag` flag returned {0}", objectResult.AsString); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # 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](https://github.com/open-feature/dotnet-sdk-contrib) repository. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - [.NET 10 SDK](https://dotnet.microsoft.com/download/dotnet/10.0) installed on your machine. | ||
|
|
||
| ## Setup | ||
|
|
||
| 1. Clone the repository: | ||
|
|
||
| ```shell | ||
| git clone https://github.com/open-feature/dotnet-sdk.git openfeature-dotnet-sdk | ||
| ``` | ||
|
|
||
| 1. Navigate to the Console sample project directory: | ||
|
|
||
| ```shell | ||
| cd openfeature-dotnet-sdk/samples/Console/Samples.Console | ||
| ``` | ||
|
|
||
| 1. Run the following command to start the application: | ||
|
|
||
| ```shell | ||
| dotnet run | ||
| ``` | ||
|
|
||
| ## Feature Flags | ||
|
|
||
| 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` | | ||
|
|
||
| ## NativeAOT | ||
|
|
||
| This sample is published with [NativeAOT](https://learn.microsoft.com/dotnet/core/deploying/native-aot/) enabled (`PublishAot=true`), demonstrating that the OpenFeature .NET SDK is fully compatible with NativeAOT compilation. See the [AOT Compatibility Guide](../../../docs/AOT_COMPATIBILITY.md) for more details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <PublishAot>true</PublishAot> | ||
| </PropertyGroup> | ||
kylejuliandev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\src\OpenFeature\OpenFeature.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.