The Policy Injection Application Block
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
|The latest Enterprise Library information can be found at the Enterprise Library site.|
The Enterprise Library Policy Injection Application Block provides a mechanism for automatically applying policies to object instances; this helps developers to better manage crosscutting concerns, maximize separation of concerns, and encapsulate behavior. Developers define the set of policies for the target classes and their members through configuration of the Policy Injection Application Block or by applying attributes to individual members of the target class.
The matching rules for each policy encompass a range of capabilities for selecting classes and members, including the name of the assembly, the namespace, the type, the member name, the member signature, attributes that are applied to the member, and more.
A factory method of the Policy Injection Application Block creates a proxy for each configured class selected by the matching rules or the directly applied attributes; the method attaches the handler pipelines to each proxy and connects them to the appropriate methods and properties of a new instance of the target object. If there are no policies for the object, the application block detects this and returns the object itself instead of a proxy to that object.
Figure 1 illustrates a high-level view of the way the Policy Injection Application Block implements a handler pipeline for a specified member of a specified class.
High-level view of the way the Policy Injection Application Block implements a handler pipeline
The handlers within each pipeline are reusable and independent of the object. Each handler can implement a specific requirement, such as validating a parameter value or checking a user's authorization status. In fact, many of the crosscutting tasks regularly occurring within applications that use Enterprise Library are calls to other application blocks within the library, such as the Validation Application Block, the Logging Application Block, the Exception Handling Application Block, the Security Application Block, and the Instrumentation and Performance Counters features of the Enterprise Library Core.
The Policy Injection Application Block ships with pre-built handlers for these application blocks that speed up development when using Enterprise Library to help manage crosscutting concerns. Developers can also create custom handlers and policies that carry out almost any required interception processing for methods and properties of their objects.
The implementation of a system that automatically creates a proxy and handler pipeline for methods is similar to the aspect-oriented programming (AOP) approach. However, the Policy Injection Application Block is not an AOP framework implementation for the following reasons:
- It uses interception to enable only pre-processing handlers and post-processing handlers.
- It does not insert code into methods.
- It does not provide interception for class constructors.
This section includes the following topics:
- Introduction to the Policy Injection Application Block
- Developing Applications Using the Policy Injection Application Block
- Key Scenarios
- Design of the Policy Injection Application Block
- Extending and Modifying the Policy Injection Application Block
- Deployment and Operations
- Policy Injection QuickStarts
For more information about aspect-oriented programming (AOP), object creation interception, and crosscutting concerns, see the following resources:
- The Unity Application Block, included with Enterprise Library, and the resources on the Unity Community Web site on CodePlex
- "Aspect-Oriented Programming Enables Better Code Encapsulation and Reuse" by Dharma Shukla, Simon Fell, and Chris Sells in MSDN Magazine: https://msdn.microsoft.com/en-us/magazine/cc301356.aspx
- "Aspect-Oriented Programming" by Matthew Deiters on MSDN: https://msdn.microsoft.com/en-us/library/aa288717(VS.71).aspx
- "Create a Custom Marshaling Implementation Using .NET Remoting and COM Interop" by Jim Sievert on MSDN: https://msdn.microsoft.com/en-us/magazine/cc164085.aspx
- "The EFx Architectural-Guidance Software Factory" by Jezz Santos on MSDN: https://msdn.microsoft.com/en-us/library/aa905331.aspx