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.
Share
Many people keep the DataContext around for the duration of the request by keeping it in the
HttpContext.Current.ItemsThereby it is also private to the request.Have a look at this blogpost by Steve Sanderson, and the UnitOfWork pattern.