Singleton class or class with static methods in an ASP.NET MVC application

Possible duplicate:
ASP.NET Singleton

I know the general differences between a singleton class and a class with static properties / methods, but I would like to know how it affects concurrency (many users registered in the application) in an ASP.NET MVC web application? For example, we save the settings in our singleton (or static properties) class. Is it likely that two users will suddenly start to see / use the same settings? I mean, if one user changes his settings (if they are stored in memory for the application runtime), will this affect the other user? As far as I know, IIS creates one w3wp.exe process for the application, so all users / visitors will be in the same process, so this can affect anything?

+5
source share
2 answers

The short answer is yes, users will see the same value for any static property. It will be shared between sessions.

Long answer: yes, and additionally, if each session tries to update common properties, at the same time you may encounter undesirable behavior, especially if a common (static) property is a type that grows dynamically (any type of collection). You need to handle concurrency when accessing or changing the values โ€‹โ€‹of common properties.

- // . , . , , . , .

, , , .

. - , . . .

+10

, . , "".

"IIS w3wp.exe , / , -?"

, ASP.Net, , .

, Out-Of-Process: http://msdn.microsoft.com/en-us/library/ms972429.aspx

+7

All Articles