I am trying to implement AOP in a existing application with the help of postsharp
The methods in the existing application will be making a particular call on the entry and exit
class Test
{
Method1()
{
Log.Start()
//code
Log.Stop()
}
Method2
{
Log.Start()
//code
Log.Stop()
}
}
Now If I declare a aspect for this say LogAspect containing
public override void OnEntry(MethodExecutionArgs args)
{
Log.Start();
}
public override void OnExit(MethodExecutionArgs args)
{
Log.Stop();
}
Now I want to use this aspect for the test class
so I do this.
[LogAspect()]
class Test
{
method1()
{
}
method2()
{
}
}
Now LogAspect will be applied to all methods of test.
But Log.Start() ,Log.Stop() is already present in method1 and method2 so they get executed twice. Is there any way the LogAspect can suppress Log.Start() and Log.Stop() in method1 and method2 and execute its own functionality alone on entry and exit. Is this possible in Postsharp if not any other solution as I am new into AOP? The core point here is minimal change required to change the existing application to aspects.