About the Policy Injection Application Block Configuration

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 uses a section within the Enterprise Library configuration to specify its behavior, in conjunction with any directly applied attributes in the target classes. Developers specify the following in the configuration:

  • One or more policies that, together, make up the set of policies for the application block.
  • One or more matching rules for each policy that is not attribute-based. The matching rules for each policy specify the target classes and members for which the Policy Injection Application Block will implement a handler pipeline. A policy is not limited to a single class or class member; depending on the matching rules, it can apply to all the members of one class, all the members of several classes, some members of one class, some members of multiple classes, or some other combination.
  • One or more handlers for each policy. The Policy Injection Application Block will add all the specified handlers to the handler pipeline for this policy. Each handler can be one of the built-in handlers that use features of the other application blocks in Enterprise Library or a custom handler.

The following extract shows an example of the configuration for the Policy Injection Application Block that uses some of the built-in matching rules and handlers provided with the application block.

<policyInjection>

  <policies>
    <add name="FirstPolicy">
      <matchingRules>
        <add name="MyMemberNameRule1"
             type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection
                  .MatchingRules.MemberNameMatchingRule,
                  Microsoft.Practices.EnterpriseLibrary.PolicyInjection,
                  Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
          <matches>
            <add match="MyMethodName" ignoreCase="true" />
            <add match="APropertyName" ignoreCase="true" />
          </matches>
        </add>
        <add match="MyTagToFind" ignoreCase="true"
             type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection
                  .MatchingRules.TagAttributeMatchingRule,
                  Microsoft.Practices.EnterpriseLibrary.PolicyInjection,
                  Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
             name="MyTagAttributeRule1" />
      </matchingRules>
      <handlers>
        <add logBehavior="After" beforeMessage="" afterMessage="" eventId="0"
             includeParameterValues="true" includeCallStack="false"
             includeCallTime="true" priority="3" severity="Information"
             type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection
                  .CallHandlers.LogCallHandler,
                   Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers,
                  Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
             name="MyLoggingHandler1" />
      </handlers>
    </add>
    <add name="AnotherPolicy">
      <matchingRules>
        <add match="MyMethod" ignoreCase="true"
             type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection
                  .MatchingRules.MethodSignatureMatchingRule,
                  Microsoft.Practices.EnterpriseLibrary.PolicyInjection,
                  Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
             name="Method Signature Matching Rule">
          <parameters>
            <parameter name="param1" typeName="System.Int32" />
            <parameter name="param2" typeName="System.String" />
          </parameters>
        </add>
      </matchingRules>
      <handlers>
        <add exceptionPolicyName="CustomerModelPolicy"
             type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection
                  .CallHandlers.ExceptionCallHandler,
                  Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers,
                  Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
             name="MyExceptionHandler1" />
        <add expirationTime="00:00:30"
             type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection
                  .CallHandlers.CachingCallHandler,
                  Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers,
                  Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
             name="Caching Handler" />
      </handlers>
    </add>
  </policies>
</policyInjection> 

The Enterprise Library contains tools to help you create and maintain the application configuration file. Figure 1 shows the Visual Studio Configuration Editor displaying the configuration file that contains the preceding extract.

Ff647783.622c2393-75ed-454d-b3a0-dc9435fa99e0(en-us,PandP.10).png

Figure 1
The Visual Studio Configuration Editor showing the Policy Injection section