I will start by specifying that I am new to Interception.
I want to replace some existing implementation of my project by bringing Interception into play, but I noticed that it actually brings me to be very tightly coupled to the AOP framework behind (either Castle.DynamicProxy
, Unity.Interception
, LinFu.AOP
, same story). What if I have to switch between them? (there are plenty of reasons why).
So, whenever I have to create different interceptors, these interceptors must comply specific AOP framework. There is always a need to carry the AOP framework specific invocation information (and thus to reference the AOP assemblies)
Simple example showing a "before" interceptor with Castle DynamicProxy:
public abstract class BeforeInterceptor : IInterceptor
{
void IInterceptor.Intercept(IInvocation invocation)
{
Before(invocation);
invocation.Proceed();
}
protected abstract void Before(IInvocation invocation);
}
As I understood, IInvocation must be carried into the interceptor implementation, for better control when method is invoked on the target.
What are your suggestions and recommendations. Maybe I am seeing this from a wrong angle.
PS: When using such libraries for DI, it is not the case, there is no such tight coupling.