Kebin Maharjan - 403 - Sep 14, 2014

Hi there,
I’ve an existing MVC application using Ninject. Currently we are using Command/CommandHandler pattern to resolve dependencies. With Ninject, I can bind/register all my CommandHandlers using convention like: 
Bind -> FromAssemblyContaining -> SelectAllClasses -> InderitedFrom -> (typeof(ICommandHandler<>))…
With the convention I don’t need to manually register every single command handler.

Is there a way to achieve this using Funq? I could utilize Funq’s container adapter and still use Ninject but I’d love to just use Funq and stay as much closer to ServiceStack’s way of doing things.

Any suggestions/ ideas would be awesome :slight_smile:


Hi Kebin, you can traverse the assembly and register all matching types with: 

    .Where(x => x.IsOrHasGenericInterfaceTypeOf(typeof(ICommandHandler<>)))
    .Each(x => container.RegisterAutoWiredType(x));

I’ve created a unit test that shows an example of this at:

Kebin Maharjan:

Awesome! Thanks Demis :slight_smile: