开发者

Singleton - How they work with ASP.NET?

When I create a singleton in my ASP.NET开发者_运维百科 application, what exactly is it's "scope"? Is the same singleton instance in memory likely to be used by more that one request from different IPs?

i.e. John puts information into a singleton via a form, and then Susie comes in and puts information into the singleton. Is it possible that John and Susie are storing information into the same instance?


Assuming that you are making a stereotypical Singleton (implementation you would see in a state-oriented environment) then that means that your singleton will be shared across the entire application and with ALL users.

static items are stored in server memory but are not on a per user basis. You would need to utilize something like the Session for that scenario.


Yes. Static Variables in ASP.net are shared across the entire application, for all users. Also be careful with static constructors, as they also run exactly once.

Microsoft has a KB Article, Troubleshooting ASP.NET applications with the use of static keywords (893666)

If you need "Per User Static Variables", Session or HttpContext.Items might be what you need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜