Export (0) Print
Expand All

The Policy Injection Application Block

Retired Content

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.

Ff647463.5ad51768-2a53-48a5-b31d-4f6db6b173ca(en-us,PandP.10).png

Figure 1
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:

More Information

For more information about aspect-oriented programming (AOP), object creation interception, and crosscutting concerns, see the following resources:


Show:
© 2014 Microsoft