I’m using Spring.NET to create my Command objects (with attached Advice) and run these in an MVC web application.
However I observed that the object I get back from
IApplicationContext ctx = ContextRegistry.GetContext();
MyObject obj = (MyObject) ctx.GetObject ("MyObject");
was not a new object, as I expected, as it had “remembered” the values from a previous request.
Worse still, I’m now suspecting that this shared instance is across the APPLICATION, and due to the multi-threaded nature of web requests, when my command executes and writes to the database this could result in a mish-mash of details being written from across multiple requests.
Are my fears founded, and is there a switch to always get me back a fresh and clean new object instead of a shared object? I feel I should still be able to use Spring IOC in my web apps.
Spring.NET web applications support an additional attribute within object definition elements that allows you to control the scope of an object:
The request, session and application scopes are only available if you use a web-aware Spring IApplicationContext implementation, such as WebApplicationContext.
http://www.springframework.net/doc-latest/reference/html/web.html#web-objectscope