You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the WithConcreteTypeDynamicRegistrations(), when injecting a range of class, where no registrations has been added, results in instantation of an item.
Other scenarios:
When using WithAutoConcreteTypeResolution the issue does not occur.
If item has been registered, then issue does not occur.
Other range interfaces (IList, ICollection etc.) results in same issue.
Injecting a range of interfaces (eg. IThing), the issue does not occur.
Setup:
class Program
{
void Main()
{
var rules = Rules
.Default
//.WithAutoConcreteTypeResolution()
.WithConcreteTypeDynamicRegistrations();
var container = new Container(rules);
container.Register<MyRegistry>();
var registry = container.Resolve<MyRegistry>();
}
}
class MyRegistry
{
public MyRegistry(IEnumerable<Thing> things)
{
/* 'things' contains a single thing */
Debugger.Break();
}
}
class Thing
{
Guid Id { get; set; }
}
Expected Behavior:
'things' should be empty.
Current behavior:
'things' contain a single item.
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: