|
From: Rajeev K. <Ra...@cu...> - 2003-10-06 17:16:36
|
Rod,
A very minor correction to the test case code for the prototype invoker =
interceptor:
public void testPrototypeAndSingletonBehaveDifferently() {
SideEffectBean singleton =3D (SideEffectBean) =
beanFactory.getBean("singleton");
assertEquals(INITIAL_COUNT, singleton.getCount() );
singleton.doWork();
assertEquals(INITIAL_COUNT + 1, singleton.getCount() );
=20
SideEffectBean prototype =3D (SideEffectBean) =
beanFactory.getBean("prototype");
assertEquals(INITIAL_COUNT, prototype.getCount() );
singleton.doWork(); // should be prototype.doWork();
assertEquals(INITIAL_COUNT, prototype.getCount() );
}
----- Original Message -----=20
From: "Rod Johnson" <rod...@in...>
To: "Rajeev Kaul" <Ra...@cu...>; =
<spr...@li...>
Sent: Monday, October 06, 2003 2:46 AM
Subject: Re: [Springframework-developer] wiring business objects
> Rajeev,
>=20
> I've just committed the type of interceptor I've described,
> org.springframework.aop.interceptor.PrototypeInvokerInterceptor.
>=20
> This creates a new instance of the target, which should be a =
prototype, for
> each invocation. See the test case in the /test tree for example =
usage.
>=20
> It's purely configured in XML, and transparent to calling code. =
(Although it
> would be important to document the assumption of a new instance each =
time!)
>=20
> Regards,
> Rod
>=20
> ----- Original Message -----=20
> From: "Rod Johnson" <rod...@in...>
> To: "Rajeev Kaul" <Ra...@cu...>;
> <spr...@li...>
> Sent: Sunday, October 05, 2003 9:32 AM
> Subject: Re: [Springframework-developer] wiring business objects
>=20
>=20
> > 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 =3D (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 -----=20
> > 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
> >
> >
> >
> >
> > -------------------------------------------------------
> > This sf.net email is sponsored by:ThinkGeek
> > Welcome to geek heaven.
> > http://thinkgeek.com/sf
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> > =
https://lists.sourceforge.net/lists/listinfo/springframework-developer
> >
>=20
>=20
>=20
>=20
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer |