Singleton Per Call Context WCF Web Request in Unity

旧时模样 提交于 2019-12-06 05:43:39

问题


I have gone through the question Singleton Per Call Context (Web Request) in Unity.

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.

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


回答1:


Andrew Oakley's Unity Lifetime Managers and 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.



来源:https://stackoverflow.com/questions/12919872/singleton-per-call-context-wcf-web-request-in-unity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!