0

One of application has below design:

Presentation layer: 1) MVC 4 (contains reference to WCF service) and using ninject DI for controller constructor inject - where interface and implementation are both on same project - MVC.

BAL and DAL 2) WCF Service

Converted to below design:

1) MVC (no service reference and removed ninject and only contains interfaces which are injecting into controller) 2) New library project (contain reference of MVC project and implementation of interfaces which are existed into MVC application) and added ninject module for DI.

3) WCF service

Problem: When I execute the first design approach then, it works fine and I found, controller injected interface instance but, when I have make loosely couple for WCF service reference and added into new separate project and move each interfaces into that separate project then, on execution of MVC application, it gives me below error:

System.MissingMethodException: No parameterless constructor defined for this object.

this looks like issue due to ninject DI.

NOTE: In MVC, project, there is no NinjectWebCommon and ServiceModule both are moved into that newly added class library project. Interfaces which are injecting into controller are existed into MVC project and its implementation existed int newly added class library project.

Please suggest me what is wrong here.

thank You

sunil
  • 5,078
  • 6
  • 28
  • 33
user3711357
  • 1,425
  • 7
  • 32
  • 54
  • in regards to "Interfaces which are injecting into controller are existed into MVC project and its implementation existed int newly added class libraryproject." - if you move the implementations into web project, does the error goes away? – Spock Jun 23 '14 at 19:41
  • Yes. But i want to keep that separate. I want - "interfaces to reside into MVC project and implementation into separte library project" reason behind this is, manager classes are callin to WCF service and i want WCF reference to be loosely couple from Web. so. So, i have kept like that, added reference of web project into `Manager library` project and try to achieve DI into web but, it does not work. – user3711357 Jun 27 '14 at 07:26
  • No question about your approach where u want to decouple the interface and the implementation. I just want to know whether it works. Since you said it is working, the next step I would try to put a break point in every ctro that Ninject try to resolve and see and which does it complain as there is no parameterless constructor. You may want to check the stack trace, or even check the inner exception thrown if it has any. Usually it should work unless your are trying to resolve an object that has a "dependent" object which has no parameterless constructor. – Spock Jun 28 '14 at 04:27
  • In web application, there is only interfaces reside and reference of nInject libraries (added by nuget). There is no ninjectcommonweb file and module file. Its all withing Manager library project. I think, there should be some configuration into MVC project example- global.asax should have some configuration but, i dont know. guide me what should be that......At present error indicate that, looking for parameter less constructor because, unable to find binding at runttime as because of module setup into another manager library project and not into MVC. guide me plz. thanks. – user3711357 Jun 28 '14 at 18:29
  • Sounds like you might have it backwards. Your MVC project is your composition root, so should be aware of Ninject so it can resolve the dependencies. This would then mean you either put all your code in the library, or interfaces in the library , implementation in the MVC app otherwise you have circular references. – Simon Halsey Jun 30 '14 at 00:32

0 Answers0