Using Unity for Aspect Oriented Programming and Interception – Part 2
Oct 25, 2013 • Amir Mohtasebi
In the previous post, I used unity in order to implement interception in an application. The implementation was very easy but at the same time very limited. For example, there is no way to limit the methods or namespaces we want to intercept.
Policy Injection provides various ways of creating matching rules. My favorite rules are Namespace Matching Rule and Member Name Matching Rule. As the names imply, the former is defining the matching namespace(s) and latter is defining the name of the member(s).
Any combination of the policies can provide us with a powerful interception rule. Policies are defined in policies section of interception as below:
In the above rule, any method starts with "Calculate" and has the namespace of AopTest will be intercepted. We need to have a call handler that is very similar to our interception class in previous post. It implements ICallHandler and handles the interception:
To start using the functionality, everything is almost the same as previous post. In this example we load configuration from "InterceptionPolicy" node:
The complete config file should look something like below: