I need to save some session/user related information in my MVC project. Since it should be unique and available throughout the lifetime of the session, I thought about "session-wide" singleton. I found several posts on this subject (for example here, here or here) but then I remembered reading this post about not using the Session object in a MVC application. Since this sounds like a generally bad idea, I thought about using the 4th version of Jon Skeet's singleton. In a couple of quick tests I wasn't able to see any violation of the singleton pattern per user session (i.e. only one object for every session was created). I might have missed something or might not have tested it correctly.
Is it safe to use this pattern for a session singleton in a MVC project (without saving the object in HttpContext.Current.Session
or HttpContext.Current.Items
)?