# Friday, April 13, 2007
« HttpContext.Current and ViewState | Main | Sunday Morning Fun »
I really don't understand why Spring and thus Spring.NET chose to default all objects or beans to singleton scoping.  I mean why?  In my experience singletons are rare magical beasts that usually only exist because they act as a sort of service locator.  When I use any plain old C# object I have to use the new keyword.  I'm comfortable with the new keyword, and would seriously miss it if all my classes were forced to be singletons right out of the box.  You can think of the code that you write as the blueprints for constructing a new instance at runtime, well I think that should apply to the XML you use to wire objects up in Spring with - blueprints for new objects, not singletons!  Instead the designers of Spring chose to default to singleton prototyping so that every object I declare in my XML config only ever exists once.  This is a serious scoping mismatch especially when writing something stateless like a web application where you want new instances for each request.

Why am I ranting about this anyway?  I ran into a very subtle state bug where I forgot to set singleton="true" on one of my ASP.NET controller objects, so each request was using the same controller class instance.  This may explain another error that the testers were getting at times: Request is not available in this context.

IoC
Friday, April 13, 2007 9:45:39 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [1]  |  Related posts:
Using Windsor IoC With ASP.NET
ASP.NET Model View Presenter with Spring.NET

Tuesday, December 04, 2007 1:57:52 PM (GMT Standard Time, UTC+00:00)
very nice
Comments are closed.