spring.net proxy factory with target type needs property virtual ?

Posted by Vince on Stack Overflow See other posts from Stack Overflow or by Vince
Published on 2010-04-29T09:02:53Z Indexed on 2010/04/29 9:07 UTC
Read the original article Hit count: 310

Filed under:
|
|
|
|

Hi all,

I'm creating spring.net proxy in code by using ProxyFactory object with ProxyTargetType to true to have a proxy on a non interfaced complex object. Proxying seems ok till i call a method on that object. The method references a public property and if this property is not virtual it's value is null.

This doesn't happen if i use Spring.Aop.Framework.AutoProxy.InheritanceBasedAopConfigurer in spring config file but in this case i can't use this because spring context doesn't own this object.

Is this normal to have such behavior or is there a tweak to perform what i want (proxying object virtual method without having to change properties virtual)? Note that i tried factory.AutoDetectInterfaces and factory.ProxyTargetAttributes values but doesn't help.

My proxy creation code:

public static T CreateMethodCallStatProxy<T>()
  {
   // Proxy factory
   ProxyFactory factory = new ProxyFactory();
   factory.AddAdvice(new CallMonitorTrackerAdvice());
   factory.ProxyTargetType = true;   

   // Create instance
   factory.Target = Activator.CreateInstance<T>();

   // Get proxy
   T proxiedClass = (T)factory.GetProxy();

   return proxiedClass;
  }

Thanks for your help

© Stack Overflow or respective owner

Related posts about spring.net

Related posts about aop