4

I am learning asp.net mvc and I am building an application that has to serve multiple clients.

Now in a typical asp.net mvc we usually have a composition root class (bootstrapper) where we do all our dependency injection(Unity in my case)

now suppose we are really talking to a wcf service how do you inject the repository?

I dont see a way to inject myRepository interface in my bootstrapper!Am I missing the obvious?

The only way of doing this is by creating the repository in my business layer.

  • asp.net mvc.Controller ---->WcfService --->BusinessLayer---->Repository

Given the above is it possible to inject the repository into the service?

When Unittesting I will we be mocking(moq)the repository injecting into the businessLayer.

any suggestions?

thanks for your time

tereško
  • 58,060
  • 25
  • 98
  • 150
user9969
  • 15,632
  • 39
  • 107
  • 175

1 Answers1

1

The solution we came up with which I don't like is to call DependencyInjection.Resolve<IBusinessLogic>() in each call on the webservice. I would definitely prefer some sort of boot-strapper to do some constructor injection into the implementer of the WCF interface. We just didn't have enough time to dig deeper into WCF.

Anyways, this link would be a great place to start down this path.

John Kalberer
  • 5,690
  • 1
  • 23
  • 27
  • thanks for your reply,that is some deep article into wcf.So from what you are saying you have to do something withing the wcf pipeline.mmmm.Why in all the asp.net mvc example they use the word "service" when it's not actually a wcf service? do you know or anybody – user9969 Jun 09 '11 at 16:50