Archive

Companion Files

The idea here is to use external files (text files or XML files) to apply aspects on the base code. The weaving can be done at any time using any technique (Compile-Time Weaving or Runtime Weaving). Even if this approach is extremely flexible and reasonably easy for the weaver developer, it may be impractical, in some situations, not to have the possibility to apply aspects to a class in the same source file as this class.

A good example is taken from the Policy Injection application Block of the Enterprise Library:

<policies>
     <add name="Authorize and Audit">
       <matchingRules>
         <add type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.MatchingRules.NamespaceMatchingRule, Microsoft.Practices.EnterpriseLibrary.PolicyInjection" 
              name="Namespace Matching Rule" 
              match="PolicyInjectionQuickStart.BusinessLogic" 
              ignoreCase="false" />
       </matchingRules>
       <handlers>
         <add name="Logging Handler" 
              type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers.LogCallHandler, Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers" 
              logBehavior="BeforeAndAfter"
              beforeMessage="Before" 
              afterMessage="After" 
              includeParameterValues="true" 
              includeCallTime="true" 
              includeCallStack="false" 
              severity="Information">
           <categories>
             <add name="Audit" />
           </categories>
         </add>
       </handlers>
    </add>
 </policies>

XML companion files may be difficult to read by humans, but they can easily be generated by interactive configuration tool.s

PostSharp can be used as a base to develop such weavers, but the integration with the build process should be customized.

Comments are closed