I'm trying to register the following combination in Simple Injector:
- Collection of (one or more) implementations of
IMyInterface
for a concrete type, e.g.Implementation1<MyClass>
andImplementation2<MyClass>
forIMyInterface<MyClass>
- Dummy collection (empty list) for the open generic type
IMyInterface<T>
as fall-back (conditional?)
This way I want to ensure that all requestors of IEnumerable<IMyInterface<T>>
will get at least an empty list or the list of real implementations; requestor of IEnumerable<IMyInterface<MyClass>>
should get enumerable instance (e.g. List<IMyInterface<MyClass>>
) with the elements Implementation1<MyClass>
and Implementation2<MyClass>
, and requestor of IEnumerable<IMyInterface<AnotherClass>>
should get Enumerable.Empty<IMyInterface<AnotherClass>>
.
The list of classes is not fixed in the registration code. I've implemented a bootstrapper collecting all implementations from assemblies.
I tried using several combinations of RegisterCollection
and RegisterConditional
, but no one fulfilled all requirements.
Is there a work-around for (not existing) RegisterCollectionConditional?
IEnumerable<IMyInterface<AnotherClass>>
should be an empty list, whileIEnumerable<IMyInterface<MyClass>>
should have two implementations. But what are the exact conditions on which you wish to makeIEnumerable<IMyInterface<AnotherClass>>
empty? Do you have any type constraints onImplementation1<T>
andImplementation2<T>
that preventImplementation1<AnotherClass>
to be a valid type? - Steven