开发者

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

开发者 https://www.devze.com 2022-12-28 08:58 出处:网络
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.

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 CallMonitorT开发者_运维技巧rackerAdvice());
   factory.ProxyTargetType = true;   

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

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

   return proxiedClass;
  }

Thanks for your help


OK so properties need to be virtual.

0

精彩评论

暂无评论...
验证码 换一张
取 消