Is the following possible with Simple Injector 4?
var types = container.GetTypesToRegister(typeof(IFoo<>), assemblies);
container.RegisterCollection(typeof(IFoo<>), types);
with
public interface IFoo<T> where T : IBar { ... }
and
public interface IBar { ... }
and in the assembly similar types can be found like the following:
public class Foo : IFoo<FooBar> { ... }
where
public class FooBar : IBar { ... }
The container verifies this registration. But when I do
container.GetAllInstances<IFoo<IBar>>();
Then the result is empty. My intention is to inject the following:
IEnumerable<IFoo<IBar>> foos
which I expect to return all closed type implementations of IFoo<> where the closed generic parameter is an implementation of IBar.
Also another point is that whenever I want to write a unit test for the service that consumes IEnumerable<IFoo<IBar>>, I'm trying to mock this with the following:
IEnumerable<IFoo<IBar>> collection = new[] { new Foo() };
new ConsumerService(collection);
Here the compiler has a hard time to convert the type Foo to IFoo<IBar>, which I think I understand (not sure..). But what I don't understand is that how Simple Injector would instantiate the types in the collection?
IBarso why do you want to get all isntances of IFoo<IBar>. Seems you just wanting to have ALL implementations and still you want them to be generic..? - Ric .Net