7 Approaches for AOP in .Net

time to read 4 min | 778 words

Here are all the ways that I can think of to add AOP to your application. This mostly focus on the interception side of things, because once you have that, everything else it just details.

Approach Advantages Disadvantages
Remoting Proxies Easy to implement, because of the .Net framework support Somewhat heavy weight
Can only be used on interfaces or MarshalByRefObjects
Deriving from ContextBoundObject Easiest to implement
Native support for call interception
Very costly in terms of performance
Compile-time subclassing
( Rhino Proxy )
Easiest to understand
Interfaces or virtual methods only
Runtime subclassing
( Castle Dynamic Proxy )
Easiest to understand
Very flexible
Complex implementation (but already exists)
Interfaces or virtual methods only
Hooking into the profiler API
( Type Mock )
Extremely powerful Performance?
Complex implementation (COM API, require separate runner, etc)
Compile time IL-weaving
( Post Sharp / Cecil )
Very powerful
Good performance
Very hard to implement
Runtime IL-weaving
( Post Sharp / Cecil )
Very powerful
Good performance
Very hard to implement