views:

128

answers:

1

Hi,

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);
            }
A: 

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

BennyM
Ok thanks i will look at this
Vince