Policy Injection Matching Rules

patterns & practices Developer Center

Download codeDownload PDFOrder Paperback

Unity includes matching rule implementations that provide a wide range of capabilities for selecting the objects and their members to which Unity will add a handler pipeline. Interception policies use the matching rules to define which methods will be intercepted.

A matching rule is essentially a predicate that Unity checks each time it intercepts object creation. If all of the specified matching rules evaluate to True for any particular invocation, the application block will create and add the handler pipeline for that policy. If any one of the matching rules does not evaluate to true, Unity generates an instance of the original object or a derived object, and does not create a proxy or a handler pipeline.

The following table lists the matching rules provided with Unity, and summarizes their use and parameters.

Matching rule

Description

Assembly Matching Rule

Selects classes in a specified assembly.

Custom Attribute Matching Rule

Selects classes or members that have an arbitrary attribute applied.

Member Name Matching Rule

Selects class members based on the member name.

Method Signature Matching Rule

Selects class methods that have a specific signature.

Namespace Matching Rule

Selects classes based on the namespace name.

Parameter Type Matching Rule

Selects class members based on the type name of a parameter for a member of the target object.

Property Matching Rule

Selects class properties by name and accessor type.

Return Type Matching Rule

Selects class members that return an object of the specified type.

Tag Attribute Matching Rule

Selects class members that carry a Tag attribute with the specified name.

Type Matching Rule

Selects classes that are of a specified type.

The following sections describe the built-in matching rules in detail:

You can also create and use custom matching rules. For more information, see Creating Policy Injection Matching Rules. For information about using interception, see Using Interception and Policy Injection.

Next Topic | Previous Topic | Home | Community