From 533aea8707973f5f2718e0c64b4470eebac825c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= <2493377+askpt@users.noreply.github.com> Date: Tue, 30 Apr 2024 16:44:15 +0100 Subject: [PATCH] Update README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com> --- README.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6cb3c35c..9285ea07 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ dotnet add package OpenFeature public async Task Example() { // Register your feature flag provider - await Api.Instance.SetProvider(new InMemoryProvider()); + Api.Instance.SetProvider(new InMemoryProvider()); // Create a new client FeatureClient client = Api.Instance.GetClient(); @@ -67,6 +67,29 @@ public async Task Example() } ``` +### DI Usage + +```csharp +// Register your feature flag provider +builder.Services.AddOpenFeature(static builder => +{ + builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton()); + builder.TryAddOpenFeatureClient(SomeFeatureProvider.Name); +}); + +// Inject the client +app.MapGet("/flag", async ([FromServices]IFeatureClient client) => + { + // Evaluate your feature flag + var flag = await client.GetBooleanValue("some_flag", true).ConfigureAwait(true); + + if (flag) + { + // Do some work + } + }) +``` + ## 🌟 Features | Status | Features | Description |