How to setup ninject when injection and Module binding (nInjectModule) into separate assembly

484 Views Asked by At

Following is project structure:

  1. MVC 4 application 1) Project is for MVC having controller has injected interfaces. 2) interfaces are existed into this application.
  2. Manager library project. 1) Project contain refernece of MVC application. 2) Implementation of each interfaces into this assembly. 3) NinjectMOdule is existed into this project where binded interface with related manager class.

PROBLEM: unable to get injected classes into web application.

it gives following error: Error No matching bindings are available, and the type is not self-bindable. Activation path: 2) Injection of dependency ILeadInformation into parameter leadInformation of constructor of type HomeController 1) Request for HomeController

1

There are 1 best solutions below

3
On

Usually in the "root" project which manages the kernel you need to load all the modules. This has to be done during initialization of the application i.E. before the application relies on the binding being there. Let's say the module which binds the ILeadInformation is called LeadModule. It would look like:

IKernel.Load<LeadModule>();

EDIT:

For your concrete scenario, you have your MVCApplication Assembly which contains the application and some interfaces and you have your Manager assembly, which references the MVCApplication assembly, like so:

Original dependencies

Now you ought to place the Composition Root in the MVCApplication assembly. But, uh no, you can't reference the Manager assembly, since that would lead to a circular dependency. So we got to fix this. We need to move the interfaces into a new assembly. And adjust the references so it will look like: splitting up into more assemblies so we don't have circular references