Singleton pattern with Web application, Not a good idea!!

Posted by Tony on Stack Overflow See other posts from Stack Overflow or by Tony
Published on 2010-04-25T17:05:43Z Indexed on 2010/04/25 17:13 UTC
Read the original article Hit count: 123

Filed under:
|

Hi

I found something funny, I notice it by luck while I was debugging other thing. I was applying MCP pattern and I made a singleton controller to be shared among all presentations.

Suddenly I figured out that some event is called once at first postback, twice if there is two postback, 100 times if there is 100 postbacks.

because Singleton is based on a static variable which hold the instance, and the static variable live across postbacks, and I wired the event assuming that it will be wired once, and rewired for each postback.

I think we should think twice before applying a singleton in a web application, or I miss something??

thanks

© Stack Overflow or respective owner

Related posts about architecture

Related posts about ASP.NET