【问题标题】:Spring.Net public property setter pointcutSpring.Net 公共属性设置器切入点
【发布时间】:2010-02-12 14:45:44
【问题描述】:

你知道 spring.net 中有什么切入点定义只拦截公共属性设置器(标准属性和自动实现属性)吗?

在此之后有没有办法按名称(Id、版本...)删除某些属性?

是否可以将切入点缩小到某个基类 (EntityBase) 的子类?

如您所见,我不是 spring.net 切入点的大师 ^^ 但我找不到信息。

其背后的想法是制作一个自动脏标志。在下面的示例中,目标是仅为数据属性设置器设置 IsDirty = True。

我现在在代码中使用定义而不是在 spring 配置文件中,但我认为这两种解决方案都应该没问题。

现有代码:

[Serializable]
    public class EntityBase
    {
        public string Id { get; set; }
        public long Version { get; set; }
        public bool IsDeleted { get; set; }
        public bool IsDirty { get; set; }
    }

[Serializable]
    public class Entity : EntityBase
    {       
        public string Data { get; set; }
    }

public class DirtyInterceptor : IMethodInterceptor
    {
        #region IMethodInterceptor Members

        public object Invoke(IMethodInvocation invocation)
        {
            object returnValue = invocation.Proceed();
            ((EntityBase)invocation.Target).IsDirty = true;
            return returnValue;
        }

        #endregion
    }

...

foreach (object item in keyCache.CachedModel.Values)
            {               
                ProxyFactory factory = new ProxyFactory(item);
                factory.AddAdvisor(new DefaultPointcutAdvisor (new SdkRegularExpressionMethodPointcut(???), new DirtyInterceptor()));
                T ent = (T)factory.GetProxy();

                returnList.Add(ent);
            }

【问题讨论】:

    标签: c# properties spring.net pointcuts


    【解决方案1】:

    您应该查看 Spring.NET 附带的 AoP 示例。 AoP 快速入门 #6 完全符合您的要求。它们位于此文件夹中:\examples\Spring\Spring.AopQuickStart

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-26
      • 2015-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-27
      相关资源
      最近更新 更多