Open A-Kjeldgaard opened 4 months ago
@A-Kjeldgaard, thank you for the example and the detailed description. I will look.
@A-Kjeldgaard What do you mean by this?
If item has been registered, then issue does not occur.
If I am registering Thing
then it will appear in the injected collection as intended.
As I understood, you would like to avoid automatic concrete type instantiation with WithConcreteTypeDynamicRegistrations
, right?
BTW, WithAutoConcreteTypeResolution
works this way because they do not Wrappers in general, including the collection one.
My expectation is: if there is no registrations where the service type is type Thing
, then no elements should appear when injecting a collection/enumerable/list.
If I add registrations for Thing
, I would expect one item in the injected collection for each registration added.
Examples of registrations:
container.RegisterInstance(new Thing { Id = Guid.NewGuid() });
container.RegisterDelegate(rc => new Thing { Id = Guid.NewGuid() });
container.Register<Thing>();
If I was to inject Thing
directly, as such:
public MyRegistry(Thing thing) { ... }
Then I would expect the container to instantiate an instance of Thing.
So to sum up, I only expect dynamic registrations to result in an instance when service type is directly requested, not when inside a range type.
Using the
WithConcreteTypeDynamicRegistrations()
, when injecting a range of class, where no registrations has been added, results in instantation of an item.Other scenarios:
WithAutoConcreteTypeResolution
the issue does not occur.IList
,ICollection
etc.) results in same issue.IThing
), the issue does not occur.Setup:
Expected Behavior: 'things' should be empty.
Current behavior: 'things' contain a single item.