Skip to content

Commit

Permalink
fix: Fix issue with DI documentation (#350)
Browse files Browse the repository at this point in the history
<!-- 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 <38759683+kylejuliandev@users.noreply.github.com>
Co-authored-by: Michael Beemer <beeme1mr@users.noreply.github.com>
  • Loading branch information
kylejuliandev and beeme1mr authored Jan 23, 2025
1 parent f994234 commit 728ae47
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,38 +379,43 @@ 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 variants = new Dictionary<string, bool> { { "on", true } };
var flags = new Dictionary<string, Flag>
{
// Resolve services or configurations as needed
var configuration = provider.GetRequiredService<IConfiguration>();
var flags = new Dictionary<string, Flag>
{
{ "feature-key", new Flag<bool>(configuration.GetValue<bool>("FeatureFlags:Key")) }
};

// Register a custom provider, such as InMemoryProvider
return new InMemoryProvider(flags);
});
{ "feature-key", new Flag<bool>(variants, "on") }
};

// Register a custom provider, such as InMemoryProvider
return new InMemoryProvider(flags);
});
});
```

#### Adding a Domain-Scoped Provider

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<string, bool> { { "on", true } };
var flags = new Dictionary<string, Flag>
{
// Resolve services or configurations as needed for the domain
var flags = new Dictionary<string, Flag>
{
{ $"{domain}-feature-key", new Flag<bool>(true) }
};

// Register a domain-scoped custom provider such as InMemoryProvider
return new InMemoryProvider(flags);
});
{ $"{domain}-feature-key", new Flag<bool>(variants, "on") }
};

// Register a domain-scoped custom provider such as InMemoryProvider
return new InMemoryProvider(flags);
});
});
```

<!-- x-hide-in-docs-start -->
Expand Down

0 comments on commit 728ae47

Please # to comment.