Member Name Matching Rule

Topics: Policy Injection Application Block
Oct 10, 2008 at 6:25 PM
I created an interceptable class

 

    public static IUspsManager Create(int eventId)
    {
        return Microsoft.Practices.EnterpriseLibrary.PolicyInjection.PolicyInjection.Create<UspsManager>(eventId); 
    }

and marked up a method with a policy injection tag.

 

    [Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Tag("Performance")]
    
public
AddressData StandardizeAddress(int eventId, AddressData address)

 

I created a new policy with a tag attribute matching rule and a performance counter handler.

<

 

policyInjection>
<
policies>
<
add name="Performance Policy">
<
matchingRules>
<add match="Performance" ignoreCase="false" type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.MatchingRules.TagAttributeMatchingRule, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Tag Attribute Matching Rule" /
</
matchingRules>
<
handlers>
<
add categoryName="Usps" instanceName="Usps.tests" useTotalCounter="true" incrementNumberOfCalls="true" incrementCallsPerSecond="true" incrementAverageCallDuration="true" incrementTotalExceptions="false" incrementExceptionsPerSecond="false" type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers.PerformanceCounterCallHandler, Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Performance Counters Handler" />
</
handlers>
</
add>
</
policies>
</
policyInjection>

I build and run it in (as a test project) and it works!  The performance counters increment...

Next, I commented out the policy injection tag 

    //[Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Tag("Performance")]
    public AddressData StandardizeAddress(int eventId, AddressData address)

and created a new member name matching rule in the existing policy for the same method in the interceptable class.

<
policyInjection>
<
policies>
<
add name="Performance Policy">
<
matchingRules>
<
add type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.MatchingRules.MemberNameMatchingRule, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Member Name Matching Rule">
<
matches>
<
add match="StandardizeAddress" ignoreCase="false" />
</
matches>
</
add>
<
add match="Performance" ignoreCase="false" type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.MatchingRules.TagAttributeMatchingRule, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Tag Attribute Matching Rule" />
</
matchingRules>
<
handlers>
<
add categoryName="Usps" instanceName="Usps.tests" useTotalCounter="true" incrementNumberOfCalls="true" incrementCallsPerSecond="true" incrementAverageCallDuration="true" incrementTotalExceptions="false" incrementExceptionsPerSecond="false" type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers.PerformanceCounterCallHandler, Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Performance Counters Handler" />
</
handlers>
</
add>
</
policies>
</
policyInjection>

I rebuild and run it and it does not work!?  The performance counters do not increment...

What am I missing?

Oct 13, 2008 at 9:07 AM
Hi,

you can try adding the member name matching rule to a new policy or delete the Tag matching rule in your "Performance Policy" Policy then add the member name matching rule.


Hope this helps.


.Kratos
Oct 13, 2008 at 2:13 PM
That's correct: all matching rules need to mach in order for a policy to apply.

Fernando
Nov 6, 2014 at 8:21 AM
Thanks Fernando,
you saved my day
Yes i could get the rule working.
didnt realize it was a AND condition applied among the rules
I thought it was a OR condition applied among the rules