Unity 中每个调用上下文的单例 WCF Web 请求 [英] Singleton Per Call Context WCF Web Request in Unity

查看:23
本文介绍了Unity 中每个调用上下文的单例 WCF Web 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经解决了Singleton Per Call Context (Web Request) 在 Unity 中.

基本上我想使用 Unity Container 为每个 wcf 请求创建一个单例对象.虽然我发现其他问题的答案对 ASP.Net Web 应用程序有帮助,但我不确定这些答案是否仍然适用于 WCF 服务.

Basically I want to create a singleton object per wcf request using Unity Container. Though I found the answers of other question helpful for the ASP.Net web application, I am not sure those answers still apply to WCF service.

问题是,在 WCF 服务中同时使用 CallContext 和 HttpContext,我们可以创建 PerCallContextOrRequestLifeTimeManager 吗?这会为每个 wcf 调用提供单例对象吗?

The questions is, Using both CallContext and HttpContext in WCF service, can we create PerCallContextOrRequestLifeTimeManager? Would that serve singleton object per wcf call?

推荐答案

Andrew Oakley 的 Unity Lifetime Managers 和 WCF.

Andrew Oakley's Unity Lifetime Managers and WCF.

他创建了 UnityOperationContextLifetimeManager 和 UnityInstnaceContextLifetimeManager.完整代码链接在博客底部.它不是最简单的实现,需要一点时间才能完全理解那里的所有功能.但是包含了很好的测试,IMO 这就是 Unity.WCF 应该有的.我自己使用了其中的几个,很高兴我做到了.

He creates both a UnityOperationContextLifetimeManager and a UnityInstnaceContextLifetimeManager. Full code is linked at the bottom of the blog. Its not the simplest implementation and takes a little time to fully understand the power of all that's there. But there are good tests included and IMO this is what Unity.WCF should have been. I've used a couple of these myself and been glad that I did.

这篇关于Unity 中每个调用上下文的单例 WCF Web 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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