다음을 통해 공유


The Property Matching Rule

The property matching rule allows developers, operators, and administrators to select individual properties of the target classes based on their name, including using wildcard characters, and the combination of accessors they implement.

Behavior of the Property Matching Rule

The property matching rule does the following:

  • It uses the value of the parameters passed to it to configure the matching rule for injection.
  • It compares each propertyName value to the name of the target object property, taking into account any wildcard characters in the match string.
  • It performs the name comparison on a non-case–sensitive basis if the ignoreCase parameter is True, or on a case-sensitive basis if the ignoreCase parameter is False.
  • It compares target object property accessors with the value specified and selects only parameters that have the appropriate combination of Get and Set accessors.
  • It returns True if the name and the combination of Get and Set accessors of the target object matches the values in the configuration; if the name and the combination of Get and Set accessors of the target object do not match the values in the configuration, it returns False.

The matching rules for a policy can be defined in configuration or created and applied to policies at run time. For more information about configuring matching rules at design time, see Configuration Files for Interception in the section Design-Time Configuration.

Creating a Property Matching Rule at Run Time

The following constructor overloads can be used when creating an instance of the PropertyMatchingRule class.

PropertyMatchingRule(string propertyName)

PropertyMatchingRule(string propertyName, PropertyMatchingOption option)

PropertyMatchingRule(string propertyName, PropertyMatchingOption option, bool ignoreCase)

PropertyMatchingRule(IEnumerable<PropertyMatchingInfo> matches)
'Usage
PropertyMatchingRule(propertyName As String)

PropertyMatchingRule(propertyName As String, option As PropertyMatchingOption)

PropertyMatchingRule(propertyName As String, option As PropertyMatchingOption, ignoreCase As Boolean)

PropertyMatchingRule(matches As IEnumerable(Of PropertyMatchingInfo))

The following table describes the parameters shown above.

Parameter

Description

propertyName

String. This is the name of the target property. It can include or consist of the * or ? wildcard characters so you can select multiple properties. You can also use square brackets [ ] to specify a range of characters. The following are examples:

Get*

*Orders

*TransactedOrder???

BusinessRules[order]Process.*

*

matches

PropertyMatchingInfo collection.The PropertyMatchingInfo class defines three items of information about each parameter that it will match:

The property name as a String.

A value from the PropertyMatchingOption enumeration that indicates if the rule should match on the Get, Set, or both for a selected parameter. Valid values are Get, Set, and GetOrSet.

A Boolean value that specifies whether the match should be carried out on a case-sensitive basis. The default is false.

ignoreCase

Boolean. This specifies whether the match should be carried out on a case-sensitive basis. The default is false.

The following code extract shows how you can add a property matching rule to a policy using the Unity interception mechanism.

myContainer.Configure<Interception>()
           .AddPolicy("MyPolicy")
           .AddMatchingRule<PropertyMatchingRule>
                (new InjectionConstructor
                    ("MyPropertyName", PropertyMatchingOption.GetOrSet,true))
           .AddCallHandler<MyCallHandler>
                ("MyValidator", 
                new ContainerControlledLifetimeManager());
'Usage
myContainer.Configure(Of Interception)() _
           .AddPolicy("MyPolicy") _
           .AddMatchingRule(Of PropertyMatchingRule) _
               (New InjectionConstructor _
                   ("MyPropertyName", PropertyMatchingOption.GetOrSet, True)) _
           .AddCallHandler(Of MyCallHandler) _
                ("MyValidator", New ContainerControlledLifetimeManager())

The code does not show how to create the container, add the Unity interception container extension, specify an interceptor, or resolve the intercepted target object. For more information about using matching rules with interception at run time, see Registering Policy Injection Components.