Thursday, September 17, 2009

Policy Injection and Unity Application block

This sample will help you understand how policy injection and Unity Application blocks can be used together to achieve Auditing.
One can leverage the matching rules shipped with Policy Injection block along with the custom Handlers option in Unity Application Block.

To be able to create Custom Handlers, one has to Implement the ICallHandler interface available in "Microsoft.Practices.Unity.InterceptionExtension"


Example:

















The ICallHandler interface has an method "Invoke" which needs to be overriden. In that method, we can write code before executing an particular method and after also.

IMethodReturn result = getNext()(input, getNext); indicates the actual execution of method. Whatever code written before this statement will be executed before the actual method call. And whatever code written after this statement will be executed after the actual method call.

And the application configuration file has to be updated with something like this;



No comments:

Post a Comment