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
Resolving last registration from multiple default services #97
Comments
Investigating further discloses that if I register both services as singletons, it works as I expect it. However, if the first registration is singleton and the next one is transient, it resolves using the singleton registration. You may ask why would I register the same service using different lifetimes. It is not me actually, it is IdentityServer4 but what they do makes sense to me too. Their I would still like to know if there is a way to make DryIoc resolve to the last registration no matter what lifetime is used during registrations. |
Unfortunately I am not able to interfere with scopes used internally within IdentityServer 4. I am also unable to change the way the services are registered internally. They only call AddSingleton for the default registration and AddTransient for the custom one. |
I mean, turn Off the implicit scoped service selection: var container = new Container(rules =>
rules.WithoutImplicitCheckForReuseMatchingScope()); |
I see. Thanks for the lead. Doesn't that mean I won't be able to take advantage of |
No, it does not mean that, cause |
I mean, based on the documentation's example: var container = new Container(rules =>
rules.WithoutImplicitCheckForReuseMatchingScope());
container.Register<I, A>(Reuse.ScopedTo("a"));
container.Register<I, B>(Reuse.ScopedTo("b"));
using (var scopeB = container.OpenScope("b"))
{
// Throws an exception because of the multiple `I` registrations found
Assert.Throws<ContainerException>(() => scopeB.Resolve<I>());
} A scope named I think the default behavior of ScopedTo, the one without having Sorry I am struggling to understand. |
Hmm, OK. I need to re-check. Maybe there is an issue here. |
Thanks in advance! |
Yeah :( from this perspective it is a problem. |
Glad we agree that it is a problem from some perspective. Please let me know if you want me to test it when you have a solution. |
I had a similar issue: #76, AliBazzi/IdentityServer4.Contrib.RedisStore#14 |
@SeriousM Thanks for more info. |
you're welcome |
@SeriousM I actually don't use the |
Fix is on the way :) |
🕺 |
@SeriousM I forgot to thank you for commenting and sharing what information you have. Thank you too. |
…ndencyInjectionRules and from DryIocAdapter as it is not needed after fixing the #97
So, does your commit mean that when using “select last registered”, the container will work, by default, the same way Microsoft’s service provider works? |
Yes, if you are using |
Great work! Thanks for your quick reaction. Too much if I ask the release date for 4.0.1? |
... in case you have |
Will release Today or Tomorrow's morning. |
It is out. |
Great! I’ll go ahead and test it ASAP. Thanks a lot for your efforts! |
…vices changed: using the factory selection rule when multiple services are matching the reuse less allocation of rule factory selection path added to the docs the example with SelectLastRegisteredFactory and Singleton and Transient service
…ndencyInjectionRules and from DryIocAdapter as it is not needed after fixing the dadhi#97
Do you have any opinion on why the following container would return the first registration of a service when multiple registrations exist? That is contrary to what
IServiceProvider
does so I am a bit confused.I am almost certain that you have implemented an option to change this behavior but I cannot find it.
Thanks for your support in advance.
The text was updated successfully, but these errors were encountered: