Web应用程序中的单例模式 [英] Singleton pattern in web applications

查看:115
本文介绍了Web应用程序中的单例模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Web应用程序中使用一个单一的数据文本模式,以便我每次都不必实例化,但是我不确定Web应用程序是如何工作的,IIS为每个连接的用户打开一个线程?如果是这样,如果我的单身人员不是线程安全的话,会发生什么?另外,对于数据文本使用单例模式可以吗?谢谢。

解决方案

许多人在请求期间将DataContext保留在 HttpContext.Current.Items 因此,该请求也是私有的。



看看的这个博客文章, UnitOfWork模式 n。


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屋!

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