PDA

View Full Version : Question on AOP and ICLoneable


alkampfer
07-05-2007, 08:04 AM
Hi,

I've created a class with all virtual methods, then I define an aspect and set Spring.NET AOP to add the aspect to the class. When I ask to Spring.NET to create the object all works well, My class is named Customer and spring creates to me a
[DecoratorAopProxy_56ee607448f64ab5991769f98b2d4731]
I was able to cast this class to a Customer object since it inherits from Customer and all works as expected.
The problem arise when I impment the ICloneable Interface on Customer object
public class Customer : ICloneable
{
public virtual object Clone() {

return new Customer(this);
}
Rest of the class is the same as before, now the cast to the Customer object does not work anymore because now the AOP had created a proxy not for the Customer class but for the ICloneable interface.

This is the XML I use to set the AOP

<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd" >

<object id="CustomerTarget" type="NorthwindTest.Entities.Customer, NorthwindTest" singleton="false" />

<object id="Customer"
type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">

<property name="isSingleton" value="false"/>
<property name="TargetName" value="CustomerTarget"/>
<property name="interceptorNames">
<list>
<value>WsSecurityAdvice</value>
</list>
</property>
</object>

<object id="WsSecurityAdvice" type="XTest.SecurityAdvice, XTest">
<property name="permittedRoles">
<list>
<value>admin</value>
</list>
</property>
</object>

<!--<object id="ProxyCreator" type="Spring.Aop.Framework.AutoProxy.DefaultAdvisorAutoP roxyCreator, Spring.Aop" />



<object id="WsSecurityAdvisor"
type="Spring.Aop.Support.RegularExpressionMethodPointcut Advisor, Spring.Aop">

<property name="advice" ref="WsSecurityAdvice" />
<property name="patterns">
<list>
<value>.*Customer.*</value>
</list>
</property>
</object>-->
</objects>

Thanks for any help.

Alk.

alkampfer
07-05-2007, 09:52 AM
Again do not pay attention to the post, I find how to force Spring to create a proxy of the class instead of proxying only the interfaces.

alk.

henryxuv
07-10-2007, 09:24 AM
can you send me your source code , how you get a class from the proxy. thank you , henryxuv@sina.com. or henryxuv@gmail.com

alkampfer
07-18-2007, 08:11 AM
Actually my problem is that spring proxyes all the interfaces of the object, so since the object implements icloneable the class was a decorator around ICloneable, but I need a real proxy that inherits from my class and override virtual method.

To access the proxyed class I remember that the proxy can be cast to some interface such as IAdvice, check the documentation for further detail.

alk.