The Parameter Type Matching Rule

Microsoft Enterprise Library 5.0

DropDown image DropDownHover image Collapse image Expand image CollapseAll image ExpandAll image Copy image CopyHover image

The parameter type matching rule allows developers, operators, and administrators to select target classes based on the type name of a parameter for a member of the target object.

Behavior of the Parameter Type Matching Rule

The parameter type 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 match value to the fully qualified namespace and class name, or just the class name, of the parameter types of members of the target object.
  • It compares each matching parameter to the value from the ParameterKind property specified in the list of parameter matches. This value can be Input, Output, InputOrOutput, or ReturnValue.
  • It performs the comparison on a non-case-sensitive basis if the ignoreCase value specified in the list of parameter matches is True, or on a case-sensitive basis if it is False.
  • It returns True if the target object member has parameters of matching types; if the target member does not have parameter of matching types, 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 Parameter Type Matching Rule at Run Time

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

C# Copy Code
ParameterTypeMatchingRule(IEnumerable<ParameterTypeMatchingInfo> matches)
Visual Basic Copy Code
ParameterTypeMatchingRule(matches As IEnumerable(Of ParameterTypeMatchingInfo))

The following table describes the parameter shown above.

Parameter

Description

matches

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

The parameter type name as a String.

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

The usage of the parameter as a value from the ParameterKind enumeration. Valid values are Input, Output, InputOrOutput, and ReturnValue.


The parameter type matching rule also exposes the ParameterMatches property as an IEnumerable collection of ParameterTypeMatchingInfo instances.

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

C# Copy Code
ParameterTypeMatchingInfo paramsUsed = new ParameterTypeMatchingInfo[]
                    {
                        new ParameterTypeMatchingInfo("System.String", false, ParameterKind.Input)
                    };
myContainer.Configure<Interception>()
           .AddPolicy("MyPolicy")
           .AddMatchingRule<ParameterTypeMatchingRule>
                (new InjectionConstructor(paramsUsed))
           .AddCallHandler<MyCallHandler>
                ("ContentValidator", 
                new ContainerControlledLifetimeManager());
Visual Basic Copy Code
Dim paramsUsed As ParameterTypeMatchingInfo() = New ParameterTypeMatchingInfo() _
    {New ParameterTypeMatchingInfo("System.String", False, ParameterKind.Input)}
myContainer.Configure(Of Interception)() _
    .AddPolicy("MyPolicy") _
    .AddMatchingRule(Of ParameterTypeMatchingRule)(New InjectionConstructor(paramsUsed)) _
    .AddCallHandler(Of MyCallHandler) _
        ("ContentValidator", 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.