|
From: Rod J. <rod...@in...> - 2003-10-05 08:33:14
|
Interesting point. Yes, if you use the <ref> element, you'll always be using
the same object regardless of whether you've specified it as a singleton or
prototype.
So you could make it a prototype and your shared handler can ask the
WebApplicationContext (which it has a reference to and can get in a
protected method) for an instance each time you use it:
BusinessObject bOcj = (BusinessObject) getBean("whatever")
This will work fine.
However, it does require coding and it does break Inversion of Control
somewhat.
I've always used this solution when I have this requirement (which hasn't
been often).
One potential solution is to add to Spring a generic AOP factory that
creates a new object before every request, yet pretends to be a plain
object. So you could set a reference to this magic factory and you would get
a new instance every time you invoked it, preserving strong typing and
simple code in your handler. This would be a new object per method call.
I might prototype this if it would be helpful to you. Or you could, if you
like. (Email me to discuss it further if you're interested.)
Regards,
Rod
----- Original Message -----
From: "Rajeev Kaul" <Ra...@cu...>
To: <spr...@li...>
Sent: Thursday, October 02, 2003 9:06 PM
Subject: [Springframework-developer] wiring business objects
What is the best way to wire business objects to the web handlers? I want
to keep a shared instance of the handlers for my web requests. But each
request must work with a new instance of a business object. If I set a
property for the "singleton" handler to a business objct, then won't it
always fetch the same instance (of business object) , no matter what I
specify for "singleton" attribute of the business object in the application
context? I am thinking of using an intermediary like a business object
factory, which will ensure that I get a new instance of the business object
every time, and not specify the business object in the application context.
Is there a better way of dealing with it in Spring?
Rajeev Kaul
Customer Care, Inc.
925 277 069
|