在Web应用程序Singleton模式 [英] Singleton pattern in web applications

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

问题描述

我使用的是单件模式在我的web应用程序的DataContext的,这样我不必每次初始化它,但是我不知道Web应用程序是如何工作的,并IIS打开一个线程为每个用户连接?如果是的话,你会happend如果我的单身是不是线程安全的?此外,它是确定要使用的DataContext的一个单例模式?谢谢你。

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.

推荐答案

很多人守在DataContext周围请求的持续时间保持在 HttpContext.Current.Items 因此它也是私有的请求。

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.

看一看这博文由史蒂夫·桑德森的UnitOfWork图案ñ。

这篇关于在Web应用程序Singleton模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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