Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions src/OpenFeature.Hosting/OpenFeatureBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,42 @@ internal static OpenFeatureBuilder AddPolicyBasedClient(this OpenFeatureBuilder
{
var policy = provider.GetRequiredService<IOptions<PolicyNameOptions>>().Value;
var name = policy.DefaultNameSelector(provider);

if (name == null)
{
return provider.GetRequiredService<IFeatureClient>();
return ResolveFeatureClient(provider);
}
return provider.GetRequiredKeyedService<IFeatureClient>(name);

return ResolveFeatureClient(provider, name);
});

return builder;
}

private static IFeatureClient ResolveFeatureClient(IServiceProvider provider, string? name = null)
{
var api = provider.GetRequiredService<Api>();
var context = provider.GetService<EvaluationContext>();
FeatureClient client;
if (name == null)
{
client = api.GetClient();
if (context is not null)
{
client.SetContext(context);
}
return client;
}

client = api.GetClient(name);
if (context is not null)
{
client.SetContext(context);
}

return client;
}

/// <summary>
/// Configures policy name options for OpenFeature using the specified options type.
/// </summary>
Expand Down