Skip to content

'WithConcreteTypeDynamicRegistrations' results in unintended instantiation #643

@A-Kjeldgaard

Description

@A-Kjeldgaard

Using the WithConcreteTypeDynamicRegistrations(), when injecting a range of class, where no registrations has been added, results in instantation of an item.

Other scenarios:

  1. When using WithAutoConcreteTypeResolution the issue does not occur.
  2. If item has been registered, then issue does not occur.
  3. Other range interfaces (IList, ICollection etc.) results in same issue.
  4. 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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions