ResolvedArrayParameter not injecting array of dependenceis

Nov 19, 2013 at 12:03 PM
Hi I've got the following constructor on one of my classes..
public JobsController(IUnitOfWork unitOfWork, IUpdateHandler<EF.Job>[] notificationHandler)
and the following registrations for my controller...
Container.RegisterType<IUpdateHandler<EF.Job>, JobNotificationHandler>();
Container.RegisterType<IUpdateHandler<EF.JobWork>, JobWorkNotificationHandler>();
Container.RegisterType<IUpdateHandler<EF.Job>, ClientSystemUpdateHandler>();

Container.RegisterType<API.JobsController>(
            new ContainerControlledLifetimeManager(),
            new InjectionConstructor(new ResolvedParameter<IUnitOfWork>(), new ResolvedArrayParameter<IUpdateHandler<EF.Job>>()));
But my notificationHandler parameter is always an empty array.

Do I need to register my IUpdateHandler<T> differently if they are going to be injected as an array or am I not doing the resolved array parameter correctly?
Nov 19, 2013 at 12:21 PM
For array resolution Unity only returns named registrations. So, if you register IUpdateHandler<T> with a name then it should be injected as an array:
Container.RegisterType<IUpdateHandler<EF.Job>, JobNotificationHandler>("EFJob_Array1");
~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Marked as answer by BenCrinion on 11/19/2013 at 5:57 AM
Nov 19, 2013 at 12:34 PM
I just tried that and still no joy. Do I need to specify the names as parameters to the ResolvedArrayParameter constructor?
Nov 19, 2013 at 12:57 PM
Alright your answer combined with using ResolvedParameter instead of ResolvedArrayParameter in the InjectionConstructor worked.
Container.RegisterType<API.JobsController>(
        new ContainerControlledLifetimeManager(),
        new InjectionConstructor(new ResolvedParameter<IUnitOfWork>(), new ResolvedParameter<IUpdateHandler<EF.Job>[]>()));
Thanks
Marked as answer by BenCrinion on 11/19/2013 at 5:57 AM
Nov 20, 2013 at 12:57 AM
Sorry didn't notice the use of ResolvedArrayParameter. ResolvedArrayParameter let's you explicitly specify what array you want injected. So using new ResolvedArrayParameter<IUpdateHandler<EF.Job>>() says to inject an empty array. ResolvedArrayParameter also takes concrete objects that get injected so unless you have a singleton or want to inject the same objects (e.g. fixed string array) then go with ResolvedParameter.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to