Applying Handlers Using Target Member Attributes

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 Policy Injection Application Block supports the application of policies to classes and class members using attributes applied directly to the target class or individual class members. This provides both an alternative and an additional technique that developers can use to add policy injection features to their applications.

The approach that uses matching rules defined in the application configuration is extremely powerful, allows fine-grained selection of target members, and gives administrators and operators the capability to change the behavior of the application after deployment by adding, editing, and removing policies. However, it also results in an application whose final behavior is outside the control of the application developer.

In some cases, the developer may need to exert complete control over a policy applied to specific classes or class members. For example, they may require logging or exception handling to occur, or they may require validation of parameter values. In these cases, the ability to use attributes applied to the classes and class members within the source code (which override any policies defined in the application configuration) adds extra functionality to the Policy Injection Application Block that they will find useful.

At run time, the Policy Injection Application Block combines policies defined in the application configuration with policies defined using directly applied attributes. However, developers can prevent the application of any policies to specific classes and class members, irrespective of the application configuration settings, by using the ApplyNoPolicies attribute.

The description for each of the handlers in the section Configuring and Using Pipeline Handlers includes details about the attribute that adds the handler to the pipeline, and its properties and behavior. For a description of the precedence rules for the application of policies defined in attributes and in the application configuration, see Attribute-based Policy Injection.