RegisterAll open and closed implementations in one call

Coordinator
Jan 26, 2014 at 12:36 PM
Hi,

Is it possible to RegisterAll a combination of open and closed generics in one call to RegisterAll?
interface ISubscriber<T> where T : class { }
class X : ISomething { }
class Y : ISomething { }
interface ISomething { }

class SubscriberX : ISubscriber<X> { }
class SubscriberY : ISubscriber<Y> { }
class Subscriber<T> : ISubscriber<T> where T : class, ISomething { }
This will register the first SubscriberX and SubscriberY
container.RegisterManyForOpenGeneric(
    typeof(ISubscriber<>),
    AccessibilityOption.PublicTypesOnly,
    (serviceType, implTypes) =>
    {
        container.RegisterAll(serviceType, implTypes);
    },
    AppDomain.CurrentDomain.GetAssemblies());
And this will register the Subscriber<T>
container.RegisterAllOpenGeneric(
    typeof(ISubscriber<>),
    typeof(Subscriber<>));

But GetAllInstances does not return everything I'm expecting
var result = container.GetAllInstances<ISubscriber<X>>();
I realise that this is due to the fact that I need to register all the implementations at the same time - is it possible to configure the container so that GetAllInstances will return a combination of open and closed implementations?
Coordinator
Jan 26, 2014 at 1:52 PM
var types = OpenGenericBatchRegistrationExtensions
    .GetTypesToRegister(
        container,
        typeof(ISubscriber<>),
        AppDomain.CurrentDomain.GetAssemblies());
    .ToList();

types.Add(typeof(Subscriber<>));

container.RegisterManyForOpenGeneric(
    typeof(ISubscriber<>),
    AccessibilityOption.PublicTypesOnly,
    container.RegisterAll,
    types);
Marked as answer by qujck on 1/26/2014 at 7:49 AM