How to Configure ExceptionCallHandler?

Topics: Exception Handling Application Block, Policy Injection Application Block
Sep 3, 2010 at 4:02 PM

I'm having a bit of trouble getting the ExceptionCallHandler configured correctly in version 5.0.  My container configuration is as follows:

var container = new UnityContainer();
container.AddNewExtension<EnterpriseLibraryCoreExtension>();
container.AddNewExtension<Interception>();
container
	.Configure<Interception>()
		.AddPolicy("DefaultPolicy")
			.AddMatchingRule("DefaultRule")
			.AddCallHandler("LogHandler")
			.AddCallHandler("ExceptionCallHandler")
	.Interception
	.Container
		.RegisterType<IMatchingRule, AttributeDrivenPolicyMatchingRule>("DefaultRule")
		.RegisterType<ICallHandler, LogCallHandler>("LogHandler", new InjectionConstructor(new ResolvedParameter<LogWriter>()))
		.RegisterType<ICallHandler, ExceptionCallHandler>("ExceptionCallHandler") //Need to resolve a policy.
		.RegisterType<ITypeToIntercept, TypeToIntercept>(
			new Interceptor<TransparentProxyInterceptor>(),
			new InterceptionBehavior<PolicyInjectionBehavior>())

Additionally I have the following policy defined in my App.Config:
<exceptionHandling>
<exceptionPolicies>
    <add name="Default-Exception-Policy">
    <exceptionTypes>
        <add name="All Exceptions" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
        postHandlingAction="NotifyRethrow">
        <exceptionHandlers>
            <add name="Default Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
            logCategory="General" eventId="100" severity="Critical" title="Exception Encountered"
            formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
            priority="5" />
        </exceptionHandlers>
        </add>
    </exceptionTypes>
    </add>
</exceptionPolicies>
</exceptionHandling>

This obviously fails because the ExceptionCallHandler registration is looking for an ExceptionPolicyImpl instance, however I'm not entirely clear how to go about configuring an InjectionConstructor to resolve the exception policy based on the exception policy name given in ExceptionCallHandlerAttribute.  For example:

[ExceptionCallHandler("Default-Exception-Policy")]
public void SomeFunction()
{
//perform operations
}

Thank You,

JPerroni

 

Sep 6, 2010 at 4:44 AM

To configure registration of the exceptioncallhandler with injection constructor:

container.RegisterType<ICallHandler, ExceptionCallHandler>("ExceptionCallHandler",
                new InjectionConstructor(
                    new ResolvedParameter(typeof(ExceptionPolicyImpl), "Default-Exception-Policy")));
 

Sarah Urmeneta
Global Technology & Solutions
Avande, Inc.
entlib.support@avanade.com

Dec 5, 2010 at 6:55 PM

Hi

Just a question...

If you define a IMatchingRule for , say, a namespace or assembly, you wotn need attributes, right?

 

Thanks

Dec 7, 2010 at 12:17 AM

You mean if you defined an IMatchingRule in the config?  Yes, because interception can be done either through config or through attributes.  But your call handler should be defined in the config as well.

Please create a new discussion thread for a different topic.

 

Sarah Urmeneta
Global Technologies & Solutions
Avande, Inc.
entlib.support@avanade.com