PDA

View Full Version : prototype proxied objects


valdis99
10-19-2005, 08:40 PM
I'm trying to proxy a prototype object, but it looks like if I just set ProxyFactoryObject.IsSingleton to false, the ITargetSource of ProxyFactoryObject still ends up being the SingletonTargetSource, not the PrototypeTargetSource. I (think) I've got a proxied prototype object by setting up something like the configuration below. My question though is shouldn't setting the 'IsSingleton' property to 'false' being doing to work of setting up the PrototypeTargetSource for me?



<object id="RealObjectTarget" type="My.RealObject" singleton="false"/>

<object id="RealObjectPrototypeTarget" type="Spring.Aop.Target.PrototypeTargetSource" singleton="false">
<property name="TargetObjectName">
<idref object="RealObjectTarget"/>
</property>
</object>

<object id="MyObject" type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">
<property name="proxyInterfaces" value="My.Interface" />
<property name="isSingleton" value="false"/>
<property name="targetName" value="RealObjectPrototypeTarget" />
<property name="interceptorNames">
<list>
<value>MyAdvise1</value>
<value>MyAdvise2</value>
</list>
</property>
</object>

Rick Evans
10-20-2005, 12:02 AM
Hi

Okay... lets take this from the top.

...shouldn't setting the 'IsSingleton' property to 'false' being doing to work of setting up the PrototypeTargetSource for me?

No. The 'IsSingleton' property controls the singletonicity (er) of the ProxyFactoryObject's GetObject() implementation (and not the target of the ProxyFactoryObject). It is there to satisfy the use case where one wants to get distinct (prototype) proxies back (all advising the same target object), and then change the configuration of said proxy on a per proxy basis (maybe one wants to add certain advice to only one of the proxies so created... I must admit that I can't think of a scenario where I would want to do this though :?).

The configuration that you have defined certainly will do what you want; we don't have an example of this in the reference documentation, so nice one :). I will add an example (http://opensource2.atlassian.com/projects/spring/browse/SPRNET-222) to the AOP guide in due course, and change the API documentation (http://opensource2.atlassian.com/projects/spring/browse/SPRNET-221) for the the 'IsSingleton' property so that it is explicit about it being the singletonicity of the proxy that is being configured via the 'IsSingleton' property value.

What is not cool is that you have exposed another bug (http://opensource2.atlassian.com/projects/spring/browse/SPRNET-223) in the AOP implementation. I guess the main gist of your post is that the configuration you have used is quite verbose (through no fault of your own I must add)... you were expecting a nicer shorthand way. Well, there is a shorthand way to do what you want... but I have just discovered that it doesn't work. I have written tests to flush the bug out, and the fix will be in place for the 1.0.1 release due out in a few weeks time. I won't post a broken config snippet on here illustrating this 'nicer' configuration right now ('cos its broken anyways), but will post back as soon as the fix is in.

Mmm, this is the second AOP bug that you have flushed out. Lets hope you don't ever get to three :D

Cheers
Rick