Interception and Interceptors in C# (Aspect oriented programming)
In this post, we see how to define specific actions to be executed before or after the execution of every call to a method in our code. This is also known as “ intercepting ” the execution of a method and is related to AOP (Aspect Oriented Programming). We will explore two different ways of achieving this: Using Microsoft’s Unity framework Using the PostSharp library CastleDynamicProxy is another library allowing you to intercept methods and resembles a lot to the Unity framework’s approach so it will not be described here. You can also use .NET framewrok’s Emit namespace or CodeDom to create your intercepting Proxy objects from scratch but this approach is out of the scope of this post. Aspect Oriented Programming deals with horizontal concerns in the specifications of your programs. Horizontal concerns are requirements that span through every business logic or specific behavior of your system. Take for example the following figure displaying some typical modules of an e-shop application. The classes
Διαβάστε περισσότερα »