Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to register a custom IFeatureProvider #22

Open
unsafecode opened this issue Apr 11, 2019 · 6 comments
Open

How to register a custom IFeatureProvider #22

unsafecode opened this issue Apr 11, 2019 · 6 comments

Comments

@unsafecode
Copy link

Looks like FeatureFlagOptions.Provider is read only outside of this lib

@unsafecode
Copy link
Author

Additionally, the implementation of method UseCachedSqlFeatureProvider violates the DI principles, by instanciating the provider directly, and making it complicated to a have real modular architecture.

I would have expected to register an additionaly provider via AddSingleton<IFeatureProvider, MyFeatureprovider>, and let the app choose one via some sort of setting

@kendaleiv
Copy link
Contributor

The internal could be removed from this set;:

public IFeatureProvider Provider { get; internal set; }

I was thinking that the extension methods would be used instead, but internal does seem to prohibit using a custom provider. Thanks for catching that!


Is there a use case where the IFeatureProvider instance needs to be part of dependency injection that can't be solved without it? Just seeking to understand, since it's possible to do this with branching logic not part of IoC.

@unsafecode
Copy link
Author

Honestly, I'd say it's more a matter of philosophy: if you adopt DI, it would be better to leverage it fully.

Additionally, the provider pattern nicely suits DI, as you can even register multiple implementations and then pick one without changing your design.

@kendaleiv
Copy link
Contributor

Added a UseCustomProvider extension method in #27. If we want to change the overall philosophy and results in a breaking change we can look into that with v2.

@unsafecode
Copy link
Author

@kendaleiv Thanks for this fix.

IMHO, it would likely be easier not to require an IFeatureProvider instance, and rather have it as a generic parameter in the same method, and then retrieve it via GetRequiredService<T>.

For instance, in the current implementation, how can I pass a registered service in my custom provider instance?

@unsafecode
Copy link
Author

/cc @Ettores88 @matteo-daverio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants