Appendix C - Policy Injection in Enterprise Library

Policy injection describes a method for inserting code between the client and an object that the client uses, in order to change the behavior of the target object without requiring any changes to that object, or to the client. The general design pattern for this technique is called interception, and has become popular through the Aspect-Oriented Programming (AOP) paradigm.

Interception has been a feature of Enterprise Library since version 3.0. In previous releases of Enterprise Library, the manner in which you would enable interception was through the Policy Injection Application Block, which exposed static facades you could use to create wrapped instances of target objects and the appropriate proxy through which the client can access that target object.

The block also contained a series of call handlers that are inserted into the interception pipeline, between the client and the target object. The same set of call handlers as used in previous versions of Enterprise Library is included in version 5.0, though they are no longer located in the Policy Injection block (which is provided mainly for backwards compatibility with existing applications).

In version 5.0 of Enterprise Library, the recommended approach for implementing policy injection is through the Unity interception mechanism. This supports several different techniques for implementing interception, including the creation of derived classes rather than remoting proxies, and it has much less impact on application performance.

The call handlers you use with the Unity interception mechanism can instantiate application blocks, allowing you to apply the capabilities of the blocks for managing crosscutting concerns for the target object. The capabilities provided by interception and policy injection through Unity and Enterprise Library allow you to:

  • Add validation capabilities by using the validation handler. This call handler uses the Validation block to validate the values passed in parameters to the target object. This is a useful approach to circumvent the limitations within the Validation block, which cannot validate parameters of method calls except in specific scenarios such as in Windows® Communication Foundation (WCF) applications.
  • Add logging capabilities to objects by using the logging handler. This call handler uses the Logging block to generate log entries and write them to configured target sources.
  • Add exception handling capabilities by using the exception handling handler. This call handler uses the Exception Handling block to implement a consistent strategy for handling, replacing, wrapping, and logging exceptions.
  • Add authorization capabilities to objects by using the authorization handler. This call handler uses the Security block to check if the caller has the required permission to execute each call.
  • Add performance measurement capabilities by using the performance counter handler. This call handler updates Windows® performance counters with each call, allowing you to measure performance and monitor target object activity.
  • Add custom behavior to objects by creating your own interception call handlers.

For more information about using Unity to implement interception, see the documentation installed with Enterprise Library or available online at

For information on how to use the Policy Injection block facade, see the documentation for version 4.1 of Enterprise Library on MSDN® at