Skip to content

Commit

Permalink
Fix issue with DI documentation
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
  • Loading branch information
kylejuliandev committed Jan 20, 2025
1 parent 1b5a0a9 commit b8d83e7
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,38 +379,44 @@ 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<IConfiguration>();
var variants = new Dictionary<string, bool> { { "on", configuration.GetValue<bool>("FeatureFlags:Key") } };
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 b8d83e7

Please sign in to comment.