Using Ninject with MVC3 controllers that are in external assemblies
-
22-03-2021 - |
Question
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?
Solution 2
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);
}
OTHER TIPS
Probably you should update Ninject. RegisterAllControllersIn
is from a version that is outdated since a long time.