Web应用程序中的单例模式 [英] Singleton pattern in web applications
本文介绍了Web应用程序中的单例模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
许多人在请求期间将DataContext保留在 HttpContext.Current.Items
因此,该请求也是私有的。
I'm using a singleton pattern for the datacontext in my web application so that I dont have to instantiate it every time, however I'm not sure how web applications work, does IIS open a thread for every user connected? if so, what would happend if my singleton is not thread safe? Also, is it OK to use a singleton pattern for the datacontext? Thanks.
解决方案
Many people keep the DataContext around for the duration of the request by keeping it in the HttpContext.Current.Items
Thereby it is also private to the request.
Have a look at this blogpost by Steve Sanderson, and the UnitOfWork pattern.
这篇关于Web应用程序中的单例模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文