views:

92

answers:

0

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