Skip to content

Calling AddContext without registering any Providers throws System.InvalidOperationException #544

@kylejuliandev

Description

@kylejuliandev

Not necessarily a bug, but rather an opportunity to improve the dependency injection experience.

If you calling AddOpenFeature and inject some EvaluationContext (see code snippet below) when resolving IFeatureClient a System.InvalidOperationException: Sequence contains no elements is thrown in OpenFeatureServiceCollectionExtensions.cs.

var options = provider.GetRequiredService<IOptions<OpenFeatureOptions>>().Value;
return options.ProviderNames.First();

Code to reproduce the exception

builder.Services.AddOpenFeature(featureBuilder =>
{
    featureBuilder
        .AddHostedFeatureLifecycle()
        .AddContext(ctx => ctx.Set("region", "euw"));
});

Is there a way we could throw an exception earlier, like say during Startup, to say that OpenFeature with Dependency Injection has not been setup correctly? Or should it fail more silently, and fallback to any default variants configured by developers?

Metadata

Metadata

Assignees

Labels

area: dependency-injectionImprovements or bugs do DIquestionFurther information is requestedtype: docsImprovements or additions to documentation

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions