简体   繁体   English

SOA问题:WCF +依赖项注入

[英]SOA issue: WCF + dependency injection

We have the following solution layout: 我们有以下解决方案布局:

  • DataAccess 数据访问
  • Business Logic 商业逻辑
  • WCF Services WCF服务
  • MVC MVC

We chose to have a WCF service layer, because in the future there will be other applications using the same logic. 我们选择了WCF服务层,因为将来还会有其他应用程序使用相同的逻辑。 That's considered to be SOA. 这被认为是SOA。

Between the DA, BL and WCF layer I tend to use dependency injection, because I'd like to unit test the Business Logic etc.. 在DA,BL和WCF层之间,我倾向于使用依赖注入,因为我想对业务逻辑等进行单元测试。

But now my question is: should I use dependency injection for the WCF as well? 但是现在我的问题是:我也应该对WCF使用依赖注入吗? What I mean is, should I pass dependencies through the WCF services from the application (consumer)? 我的意思是,我是否应该通过应用程序(消费者)的WCF服务传递依赖关系? Personally I find that weird, because it then no longer seems SOA to me? 我个人觉得很奇怪,因为对我而言,现在它不再是SOA了?

Can anyone help me out? 谁能帮我吗?

Might be nitpicking, but using services doesn't mean necessarily SOA. 也许有些挑剔,但是使用服务并不一定意味着SOA。

With that out of our way, why would you need to pass dependencies from the application? 有了这种方式,您为什么需要从应用程序传递依赖关系? You can compose your services on the host as shown here . 您可以按如下所示主机上组合服务。

If you want to unit test business logic you can even declare different end points for them and consume then in your unit testing, it's an alternate of dependency injection. 如果要对业务逻辑进行单元测试,甚至可以为它们声明不同的端点并使用它们,那么在单元测试中,这是依赖项注入的替代方法。 And if you really want to use dependency injection then it is always advisable to do it on service level rather then on client but still there is no harm if you use it from client. 而且,如果您确实要使用依赖项注入,那么建议始终在服务级别上而不是在客户端上进行依赖注入,但是如果从客户端使用它也没有危害。 If i would given choice then i would have done it in Service class and from client i could get a parameter which will suggest whether your are using it for unit testing or application has made an call to your WCF service. 如果我可以选择的话,那么我将在Service类中完成它,并且可以从客户端获得一个参数,该参数将建议您是将其用于单元测试还是应用程序调用了WCF服务。

should I pass dependencies through the WCF services from the application? 我应该通过应用程序的WCF服务传递依赖项吗?

I guess the application you mean the consumer of the WCF service right? 我猜您认为WCF服务使用者的应用程序对吗? I believe from the application(MVC) you are talking to the service layer through proxies. 我相信从应用程序(MVC)您正在通过代理与服务层对话。 You should not inject dependencies to a WCF service from the consumer application and you can't do that. 您不应从使用者应用程序向WCF服务注入依赖项,也不能这样做。

But you can use dependency injection in WCF to inject data/logging components for better unit testing in the service side itself by creating custom service host factory. 但是,您可以在WCF中使用依赖项注入通过创建自定义服务宿主工厂来注入数据/日志记录组件,以便在服务端本身进行更好的单元测试。

http://prideparrot.com/blog/archive/2012/2/dependency_injection_in_wcf_using_castle_windsor http://prideparrot.com/blog/archive/2012/2/dependency_injection_in_wcf_using_castle_windsor

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM