Call handlers in unity interception configuration

Oct 6, 2010 at 4:13 AM

I have the following unity configuration, which contain the policy injection configuration for log call handler. The parameters under call handler doesn't allow to specify the log categories. Does anyone has any examples on how to specify these categories in the config file?

 <container name="TestContainer">
        <extension type="Interception"/>

        <interception>
          <policy name="Logging Policy">
            <matchingRule name="Namespace Matching Rule" type="NamespaceMatchingRule">
              <constructor>
                <param name="namespaceName" value="ATK.Common.Delegate.UnitTest.*"></param>
              </constructor>
            </matchingRule>
            <callHandler name="Logging Handler" type="LogCallHandler">
              
              <constructor>
                
              </constructor>
                <property name="LogBeforeCall" value="true" />
                <property name="LogAfterCall" value="true" />
                <property name="BeforeMessage" value="Method call started" />
                <property name="AfterMessage" value="Method call completed" />
                <property name="IncludeParameters" value="true" />
                <property name="IncludeCallStack" value="false" />
                <property name="IncludeCallTime" value="true" />
                
                <!--<property name="Categories" value="Audit Category" />-->
              </callHandler>
          </policy>
        </interception>

        <register type="testContract" mapTo="testConcrete" name="TestMap">
          <constructor>
            
          </constructor>
          <policyInjection/>
        </register>
        <register type="testConcreteMarshal" name="TestMapMarshal">
          <constructor>
            
          </constructor>
          <policyInjection/>
        </register>
        
      </container>
  </unity>

Oct 6, 2010 at 9:12 AM
Edited Oct 6, 2010 at 9:59 AM

Before answering your question, you should also configure the value for the LogWriter.  You can use the sample constructor injection posted in this thread.  Make sure to add the EnterpriseLibraryCoreExtension in your unity container.

On the matter of configuring the Categories property, you would create a custom type converter to convert the value you specified in the config to a list of string.

<property name="Categories">
         <value value="General, File" typeConverter="StringToListConverter" />
</property>

Where StringToListConverter is a defined type alias for your custom converter.

Sample code for the custom converter:

public class StringToListConverter : TypeConverter
{

        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            if (value != null)
            {
                string configValues = value.ToString();
                if (!string.IsNullOrEmpty(configValues))
                {
                    string[] categories = configValues.Split(',');
                    return categories.ToList();
                }
            }
            return new List<string>();
        }

}

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Oct 6, 2010 at 7:29 PM

This works. Thanks for the help.

Oct 8, 2010 at 12:32 AM

Can we use the same approach for configuring the exception policy also? I couldn't find any documentation related to this area.

Basically I want to know the list of properties that can be configured for each call handler?

 

 

Oct 8, 2010 at 2:41 AM
Edited Oct 8, 2010 at 3:25 AM

Yes, you could use the same approach.  I suggest configuring constructor injection rather than properties so you wouldn't miss anything.  Just look for the constructor of the call handler you want to configure.  For example, for the ExceptionCallHandler, it has a constructor which takes an ExceptionPolicyImpl and another one which takes an ExceptionPolicyImpl and an integer for the Order property.  An ExceptionPolicyImpl object maps to an exception policy you defined in your exceptionHandling settings.  

Suppose you have an exception policy named "General Policy" defined in your config, here's how its call handler would be configured if you want to use the constructor public ExceptionCallHandler(ExceptionPolicyImpl exceptionPolicy)

<callHandler type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.PolicyInjection.ExceptionCallHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" name="exception handler">
	<constructor>
		<param name="exceptionPolicy" dependencyName="General Policy" />
	</constructor>
</callHandler>

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com