In my case, a certain class does not depend on one object, but on its collection:
public class ImportController { ...
public ImportController(IEnumerable<IImportManager> managers) { ... }
}
public class ProductAImportManager : IImportManager { ... }
public class ProductBImportManager : IImportManager { ... }
public class ProductCImportManager : IImportManager { ... }
I want to create an instance of ImportController using Unity, so how do I register dependencies?
If I use something like
unityContainer.RegisterType<IImportManager, ProductAImportManager>();
unityContainer.RegisterType<IImportManager, ProductBImportManager>();
the second call simply overrides the first.
Can I ask Unity to find all registered types that implement the IImportManager interface, create these types and pass a sequence of objects to my constructor?
source
share