Search code examples
c#asp.net-mvc-4dependency-injectiondryioc

Registering an assembly is also registering enums


I am using DRYIOC for DI in my application. I have interfaces in my MVC application which I want to register to dryIOC. So I am using RegisterMany as below.

container.RegisterMany(new[] { Assembly.Load(DIAssemblyCollection["WebAssembly"]) }, 
    serviceTypeCondition: type => type.IsInterface, 
    setup: Setup.With(allowDisposableTransient: true));

But I am getting the error as below

Unspecified how to select single constructor for implementation type Web.Enums.Enum1 with 0 public constructors.


Solution

  • Seems like a bug, but need to look at code first.

    Meanwhile you can just filter implementation types, keep classes only:

    container.RegisterMany(
        Assembly.Load(DIAssemblyCollection["WebAssembly"])
            .GetLoadedTypes()
            .Where(type => type.IsClass), 
        serviceTypeCondition: type => type.IsInterface, 
        setup: Setup.With(allowDisposableTransient: true));
    

    Live example

    Update

    Fixed in DryIoc 2.7