From b8d83e76f82ab28c35eeeb709c179e1d16d4b6af Mon Sep 17 00:00:00 2001 From: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com> Date: Mon, 20 Jan 2025 19:57:13 +0000 Subject: [PATCH] Fix issue with DI documentation Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com> --- README.md | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 0aaeb399..993bb2ec 100644 --- a/README.md +++ b/README.md @@ -379,19 +379,22 @@ builder.Services.AddOpenFeature(featureBuilder => { You can register a custom provider, such as `InMemoryProvider`, with OpenFeature using the `AddProvider` method. This approach allows you to dynamically resolve services or configurations during registration. ```csharp -services.AddOpenFeature() - .AddProvider(provider => +services.AddOpenFeature(builder => +{ + builder.AddProvider(provider => + { + // Resolve services or configurations as needed + var configuration = provider.GetRequiredService(); + var variants = new Dictionary { { "on", configuration.GetValue("FeatureFlags:Key") } }; + var flags = new Dictionary { - // Resolve services or configurations as needed - var configuration = provider.GetRequiredService(); - var flags = new Dictionary - { - { "feature-key", new Flag(configuration.GetValue("FeatureFlags:Key")) } - }; - - // Register a custom provider, such as InMemoryProvider - return new InMemoryProvider(flags); - }); + { "feature-key", new Flag(variants, "on") } + }; + + // Register a custom provider, such as InMemoryProvider + return new InMemoryProvider(flags); + }); +}); ``` #### Adding a Domain-Scoped Provider @@ -399,18 +402,21 @@ services.AddOpenFeature() You can also register a domain-scoped custom provider, enabling configurations specific to each domain: ```csharp -services.AddOpenFeature() - .AddProvider("my-domain", (provider, domain) => +services.AddOpenFeature(builder => +{ + builder.AddProvider("my-domain", (provider, domain) => + { + // Resolve services or configurations as needed for the domain + var variants = new Dictionary { { "on", true } }; + var flags = new Dictionary { - // Resolve services or configurations as needed for the domain - var flags = new Dictionary - { - { $"{domain}-feature-key", new Flag(true) } - }; - - // Register a domain-scoped custom provider such as InMemoryProvider - return new InMemoryProvider(flags); - }); + { $"{domain}-feature-key", new Flag(variants, "on") } + }; + + // Register a domain-scoped custom provider such as InMemoryProvider + return new InMemoryProvider(flags); + }); +}); ```