0

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

user3711357
  • 1,425
  • 7
  • 32
  • 54

1 Answers1

0

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

BatteryBackupUnit
  • 12,934
  • 1
  • 42
  • 68
  • Ya, I did this but, it is inside the Manager library and not into the MVC application. Because, MVC application contains Interfaces only and its implementation are inside the Manager project. Please guide me how i could setup in this case when - `LeadModule`,`Implementation` and `IKernel.Load();` are withing manager library project. and its related interfaces are existed insdie the WEB MVC project. Manager library project contain reference of WEB MVC project. – user3711357 Jul 03 '14 at 10:05
  • Please look into "Composite Root": http://stackoverflow.com/questions/6277771/what-is-a-composition-root-in-the-context-of-dependency-injection and http://blog.ploeh.dk/2011/07/28/CompositionRoot/ are covering that topic. – BatteryBackupUnit Jul 03 '14 at 10:44
  • As a simple summary, you can have n (any number) assemblies which define bindings in `INinjectModule`'s. However, there is one place (the composite root), where you will gather all Modules and load them into the kernel. You can also do this by convention, this means you don't need to reference the assemblies explicitly but rather you can p.Ex. search all assemblies in the execution path for implementation of `INinjectModule` and load all these (this is about the simplest variant). – BatteryBackupUnit Jul 03 '14 at 10:46