If you take the bbaia approach, this might look like an example below. This is a little simplified, but you can apply it to your situation. Suppose we have an IDoWorkForSomeTime interface with a single time parameter:
public interface IDoWorkForSomeTime { void Work(int time); }
It is implemented using TimeBoundWorker and AdvisedTimeBoundWorker :
public class TimeBoundWorker : IDoWorkForSomeTime { public void Work(int time) { Console.WriteLine("Working for {0} hours", time); } } public class AdvisedTimeBoundWorker : IDoWorkForSomeTime { [ChangeParameter] public void Work(int time) { Console.WriteLine("Working for {0} hours", time); } }
Then we can configure the AOP proxy to change the time parameter at runtime, so when we run the following program:
class Program { static void Main(string[] args) { IApplicationContext ctx = new XmlApplicationContext("objects.xml"); var worker = (IDoWorkForSomeTime)ctx.GetObject("plainWorker"); var advisedWorker = (IDoWorkForSomeTime)ctx.GetObject("advisedWorker"); worker.Work(4); advisedWorker.Work(4); } }
It outputs:
Working for 4 hours Working for 8 hours
So, although I call it the value 4, advisedWorker uses the value 8, which I configured in my spring configuration file. The spring container sees the [ChangeParameter] attribute and knows from my configuration that it should use the following interceptor method:
public class ChangeParamInterceptor : IMethodInterceptor { public int NewValue { get; set; }
This requires the spring configuration in objects.xml :
<?xml version="1.0" encoding="utf-8" ?> <objects xmlns="http://www.springframework.net"> <object id="plainWorker" type="Examples.Aop.Shared.TimeBoundWorker, Examples.Aop.Shared" singleton="true"> </object> <object id="advisedWorker" type="Examples.Aop.Shared.AdvisedTimeBoundWorker, Examples.Aop.Shared" singleton="true"> </object> <object id="changeParamAdvice" type="Examples.Aop.Shared.ChangeParamInterceptor, Examples.Aop.Shared"> <property name="NewValue" value="8" /> </object> <object id="attributePointcut" type="Spring.Aop.Support.AttributeMatchMethodPointcut, Spring.Aop"> <property name="Attribute" value="Examples.Aop.Shared.ChangeParameterAttribute, Examples.Aop.Shared" /> </object> <object id="changeParamAspect" type="Spring.Aop.Support.DefaultPointcutAdvisor, Spring.Aop"> <property name="Pointcut" ref="attributePointcut" /> <property name="Advice" ref="changeParamAdvice"/> </object> <object id="ProxyCreator" type="Spring.Aop.Framework.AutoProxy.DefaultAdvisorAutoProxyCreator, Spring.Aop" /> </objects>
You have many more options for setting up AOP and applying tips like ChangeParamInterceptor . Read more in the Spring .NET Documentation on AOP .