Skip to content

Commit 728ae47

Browse files
fix: Fix issue with DI documentation (#350)
<!-- Please use this template for your pull request. --> <!-- Please use the sections that you need and delete other sections --> ## This PR <!-- add the description of the PR here --> - Addresses issue with the README documentation for Dependency Injection Providers. ### Related Issues <!-- add here the GitHub issue that this PR resolves if applicable --> Fixes #349 ### Notes <!-- any additional notes for this PR --> ### Follow-up Tasks <!-- anything that is related to this PR but not done here should be noted under this section --> <!-- if there is a need for a new issue, please link it here --> ### How to test <!-- if applicable, add testing instructions under this section --> --------- Signed-off-by: Kyle Julian <[email protected]> Co-authored-by: Michael Beemer <[email protected]>
1 parent f994234 commit 728ae47

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

README.md

+28-23
Original file line numberDiff line numberDiff line change
@@ -379,38 +379,43 @@ builder.Services.AddOpenFeature(featureBuilder => {
379379
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.
380380

381381
```csharp
382-
services.AddOpenFeature()
383-
.AddProvider(provider =>
382+
services.AddOpenFeature(builder =>
383+
{
384+
builder.AddProvider(provider =>
385+
{
386+
// Resolve services or configurations as needed
387+
var variants = new Dictionary<string, bool> { { "on", true } };
388+
var flags = new Dictionary<string, Flag>
384389
{
385-
// Resolve services or configurations as needed
386-
var configuration = provider.GetRequiredService<IConfiguration>();
387-
var flags = new Dictionary<string, Flag>
388-
{
389-
{ "feature-key", new Flag<bool>(configuration.GetValue<bool>("FeatureFlags:Key")) }
390-
};
391-
392-
// Register a custom provider, such as InMemoryProvider
393-
return new InMemoryProvider(flags);
394-
});
390+
{ "feature-key", new Flag<bool>(variants, "on") }
391+
};
392+
393+
// Register a custom provider, such as InMemoryProvider
394+
return new InMemoryProvider(flags);
395+
});
396+
});
395397
```
396398

397399
#### Adding a Domain-Scoped Provider
398400

399401
You can also register a domain-scoped custom provider, enabling configurations specific to each domain:
400402

401403
```csharp
402-
services.AddOpenFeature()
403-
.AddProvider("my-domain", (provider, domain) =>
404+
services.AddOpenFeature(builder =>
405+
{
406+
builder.AddProvider("my-domain", (provider, domain) =>
407+
{
408+
// Resolve services or configurations as needed for the domain
409+
var variants = new Dictionary<string, bool> { { "on", true } };
410+
var flags = new Dictionary<string, Flag>
404411
{
405-
// Resolve services or configurations as needed for the domain
406-
var flags = new Dictionary<string, Flag>
407-
{
408-
{ $"{domain}-feature-key", new Flag<bool>(true) }
409-
};
410-
411-
// Register a domain-scoped custom provider such as InMemoryProvider
412-
return new InMemoryProvider(flags);
413-
});
412+
{ $"{domain}-feature-key", new Flag<bool>(variants, "on") }
413+
};
414+
415+
// Register a domain-scoped custom provider such as InMemoryProvider
416+
return new InMemoryProvider(flags);
417+
});
418+
});
414419
```
415420

416421
<!-- x-hide-in-docs-start -->

0 commit comments

Comments
 (0)