Singleton pattern in web applications

.net, c#, design-patterns, singleton

Solution

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.

Problem

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.

Original source