Closed jbrookssmokeball closed 1 year ago
Yeah, there is some bug here. But I am not sure why do you do the registration twice, is it intended?
Anyway, if you comment the first registrations which do not do anything because they are overridden by the next, there will be no bug. I mean to comment those:
container.RegisterMany(new[] { typeof(Foo1), typeof(IFoo) }, typeof(Foo1), reuse: Reuse.Singleton);
container.RegisterMany(new[] { typeof(Foo2), typeof(IFoo) }, typeof(Foo2), reuse: Reuse.Singleton);
@dadhi yep you're right, it will work with just the second registration by itself. Found this bug when implementing DryIoc on a legacy DI abstraction which required me to register it a second time in order to get property injection so thought I'd raise it. I am unable to work around it using IfAlreadyRegistered.Replace
unfortunately as this will replace the first registration for the interface too i.e. resolving an IEnumerable<IFoo>
in this case will then only return Foo2
.
@jbrookssmokeball thanks for clarifying.
Property injection is not working correctly when appending a new implementation for multiple registrations of the same interface and injecting an enumerable of the interface.
It works fine if building the concrete type, but when injecting the enumerable of the interface it gives a null value on the second registered type.
For example you have the following interface and classes:
Then when registering each implementation in the container twice (appending the implementation with a property selector the second time) only
Foo1
will have the property set when resolving anIEnumerable
ofIFoo
.Foo2
hasnull
for theTest
property and is a different instance to resolvingFoo2
directly (which has the property set correctly) despite being registered as a singleton.Issue for PR https://github.com/dadhi/DryIoc/pull/534