Spring.Net 公共属性设置器切入点
您知道 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该看一下 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