Enterprise Library Call Handlers
Call Handlers are Enterprise Library's extension mechanism. They allow code to be injected before or after a method is called. Enterprise Library, as of version 4.1, comes with the following call handlers and associated handler attributes, in assembly Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers:
-
AuthorizationCallHandler / AuthorizationCallHandlerAttribute
-
CachingCallHandler / CachingCallHandlerAttribute
-
ExceptionCallHandler / ExceptionCallHandlerAttribute
-
LogCallHandler / LogCallHandlerAttribute
-
PerformanceCounterCallHandler / PerformanceCounterCallHandlerAttribute
-
ValidationCallHandler / ValidationCallHandlerAttribute
If you know the Enterprise Library, you can easily guess their meaning from their names.
I have written two additional call handlers:
-
TransactionCallHandlerAttribute (implements ICallHandler): wraps the target method in a transaction scope
-
TriesCallHandlerAttribute (implements ICallHandler): tries to invoke the target method a number of times, while an exception is thrown
For simplicity's sake, I have implemented ICallHandler in the attribute class, so the ICallHandler.CreateHandler method only returns this.
Usage is like this:
[TransactionCallHandler(TransactionScopeOption.Required)]
void SomeMethod();
and
[TriesCallHandler(3, Delay = 500)]
void SomeOtherMethod();
Enjoy!