通过IoC容器进行WCF服务实例化 [英] WCF service instantiation via IoC container

查看:137
本文介绍了通过IoC容器进行WCF服务实例化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使WCF运行时通过IoC容器而不是通过其通常的过程实例化服务? (此外,考虑到该类型的容器的生活方式配置与服务的InstanceContextBehavior之间可能存在冲突,这种方法会是一个糟糕的主意吗?)

我知道我可能完全是在问一个错误的问题.我的目标是通过容器提供的方法拦截工具进行AOP方法(例如,方法进入/退出日志记录,性能计数和调用限制,所有这些都涉及我不想插入到我的服务实现中的逻辑和依赖项).我想WCF提供了其他方法来解决此问题,所以我也很想听到其他推荐的方法.

解决方案

是的,这是同时使用ObjectBuilder和Spring.NET的实现(如果您点击链接,还会执行更多操作!):<​​/p>

http://www.infoq.com/news/2008/01 /wcf-di

但是无法评论生活方式和实例上下文行为的交互.

对于更多特定于WCF的方法,利用WCF的行为概念(如上面的示例所示)也可能是有用的.有几种不同的类型,这是一个起点:

http://mehranikoo.net/CS/archive/2007 /02/22/WCFBehaviours.aspx

干杯,
马特

Can the WCF runtime be made to instantiate a service via an IoC container rather than via its usual process? (Also, given a potential clash between the container's lifestyle configuration for the type and the service's InstanceContextBehavior, would this approach be a terrible idea?)

I'm aware that I might be asking the wrong question altogether. My objective is an AOP approach via method interception facilities provided by the container (for example, method enter/exit logging, perf counting, and call throttling, all involving logic and dependencies that I do not want to insert into my service implementation). I imagine WCF provides other ways to approach this, so I would also be curious to hear other recommended approaches.

解决方案

Yes, heres implementations using both ObjectBuilder and Spring.NET (and more if you follow the links!):

http://www.infoq.com/news/2008/01/wcf-di

Can't comment on lifestyle and instance context behavior interaction though.

As for more WCF-specific approaches, leveraging WCFs behaviors concept (as the above example does) may also be useful. There are several different types, heres a starting point:

http://mehranikoo.net/CS/archive/2007/02/22/WCFBehaviours.aspx

Cheers,
Matt

这篇关于通过IoC容器进行WCF服务实例化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆