开发者

How do you inject a repository into a wcf Service?

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 开发者_如何学Goto 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜