PDA

View Full Version : Exception while using ExposeProxy-flag and per-proxy objects


andi.kal
04-12-2006, 10:56 AM
Hej hej!

It's my first post here, so first thanks to all working so hard in this forum.

But directly back to my problem:

I have a configuration using proxies which proxy some services and have some advices attached to do some transaction handling.
This all works well with the following configuration:

...

<object id="Service1"
type="Service1Impl" singleton="false"/>

<object name="Service1Proxy"
type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop" >
<property name="isSingleton" value="false"/>
<property name="targetName" value="Service1"/>
<property name="ExposeProxy" value="false" />
<property name="interceptorNames">
<list>
<value>Interceptor1</value>
<value>Interceptor2</value>
<value>Interceptor3</value>
</list>
</property>
</object>

<object id="Interceptor1"
type="Interceptor1Impl" />
<object id="Interceptor2"
type="Interceptor2Impl" />
<object id="Interceptor3"
type="Interceptor3Impl" />

...

But now I need in a throws-advice the reference to the target object. I tried it the way described in the spring .NET reference by setting the exposeProxy flag to true.
But anytime I do this I get a System.NullReferenceException when I try to access the proxy object with different clients at the same time.

Object reference not set to an instance of an object.
at Spring.Aop.Framework.AopContext.PushProxy(Object proxy)
at Spring.Aop.DynamicProxy.Proxy_33a617e31daa438eb36f 5f900b1932b9.createMovement(ProductMovementTransfe rObject to)
at ThreadTestApp.Class1.createProductMovement() in c:\\documents and settings\\administrator\\my documents\\threadtestapp\\class1.cs:line 48

Is there any other way to access the target object in a throws advice. Other than in before or after advices the target is not provided in the parameter list of the interceptor method.

Thanks in advance,
Andi Kal.

Bruno Baia
04-12-2006, 01:58 PM
Hi Andi,

See http://www.springframework.net/doc/reference/html/aop.html#aop-introduction-advice-types-throws for the IThrowsAdvice.

You can have access to the target object, it looks like this :

public class MyThrowsAdvice : IThrowsAdvice
{
public void AfterThrowing(MethodInfo method, object[] args, object target, MyException ex)
{
// Do something will all arguments
}
}



-Bruno

andi.kal
04-12-2006, 02:46 PM
Thanks a lot!

It's really working AND it's mentioned in the reference paper!!!
So I must rub my eyes twice next time to see the relevant section...

/Andi Kal.