Using Ninject with MVC3 controllers that are in external assemblies

328 Views Asked by At

I have MVC3 controllers in external assemblies using MVC contrib's portable areas but I'm having a problem getting Ninject to inject the constructor dependencies.

The controller is found but I get an exception of "No parameterless constructor defined for this object". I can see that ninject's controller factory is being called in the call stack but for external assemblies it just does not pass my database session.

Why could this be?

2

There are 2 best solutions below

0
Max On BEST ANSWER

You need to register the controllers in the other assemblies using Ninject's RegisterAllControllersIn method.

This is my implementation in the applicationstarted method of global.asax:

        foreach (var ass in BuildManager.GetReferencedAssemblies().Cast<Assembly>())
        {
            RegisterAllControllersIn(ass);
        }
0
Remo Gloor On

Probably you should update Ninject. RegisterAllControllersIn is from a version that is outdated since a long time.