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?

Was it helpful?

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top