Spring.Net 公共属性设置器切入点

发布于 2024-08-20 20:48:51 字数 1462 浏览 11 评论 0原文

您知道 spring.net 中的任何切入点定义仅拦截公共属性设置器(标准属性和自动实现属性)吗?

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

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

正如你所看到的,我不是 spring.net pointcuts 的大师 ^^ 但我找不到信息。

其背后的想法是制作一个自动脏标志。在下面的示例中,目标是仅为数据属性设置器设置 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);
            }

Do you know any pointcut definition in spring.net to intercept only public property setter (standard properties and auto-implement properties)?

Is there a way after this to remove some property by name (Id, Version...)?

Is it possible possible to narrow pointcut to children of a certain base class (EntityBase)?

As you can see i'm not a master at spring.net pointcuts ^^ But i can't find info.

The idea behind that is to make an automatic dirty flag. In the example below the goal is to set IsDirty = True only for data property setter.

I'm using for now definition in code not in spring config file but both solutions should be ok i think.

Existing code:

[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);
            }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月朦胧 2024-08-27 20:48:51

您应该看一下 Spring.NET 附带的 AoP 示例。 AoP Quickstart #6 正是您想要的。它们位于此文件夹中:\examples\Spring\Spring.AopQuickStart

You should take a look at the AoP examples that ship with Spring.NET. AoP Quickstart #6 does exactly what you seem to be looking for. They are located in this folder: \examples\Spring\Spring.AopQuickStart

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文