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
Question: AddOptions<T>() vs. Multiple Configure<T>(…) #514
Comments
And So both APIs are interchangeable. And you can expect the
No, you can register any number of implementations for the same service type. While it is true that the normal service resolution will only give you a single instance, which will then be the latest registered dependency for that type, the options framework will resolve an |
Thanks for the reply @poke . Doesn't resolving |
The only special thing But no, resolving with If you just inject |
Thanks! That explanation was very helpful. One last question: I assume the "you will only get the implementation that was registered last" behavior is dependent on the |
Hmm, I’m not too sure about other implementations and how much of that behavior is required by Some containers may then choose not to make multiple registrations for But since ASP.NET Core requires this behavior for some of the things to work, I would assume that you can expect this to work for all DI containers that integrate with ASP.NET Core. |
I've been writing code like the following in my projects in
Startup.cs
:and i'm wondering if I should expect this to continue working, or if it is just coincidence and I should switch to the following:
Some more context: the reason i'm asking this is because i see that in the first example both of those
Configure<TOptions>(…)
methods useservices.AddSingleton<IConfigureOptions<TOptions>>(…)
under the hood, and -- although each uses a different type for the implementation instance -- i was under the impression that the number of registrations for a service type is restricted to one, either byServiceCollection
orServiceProvider
The text was updated successfully, but these errors were encountered: