In our external boundaries that expose WCF services, we convert all internal exceptions to FaultException
. This is a manual process which often has minor flaws unique to each implementation. It has been copy/pasted and mindlessly modified (or forgotten) for each exposed method. To reduce the errors, I wanted to create an aspect which would catch any unhandled exception.
We do a mapping of internal exceptions to fault exceptions. How can I send a mapping function to the aspect?
If I add a property to the aspect like this:
[Serializable]
public sealed class FaultExceptionConverter : OnExceptionAspect {
public Func<Exception, FaultException> FaultConverter { get; set }
}
I cannot (as expected by Attribute restrictions) initialize it like [FaultExceptionConverter(FaultConverter = MyConversionMethod)]
(where MyConversionMethod
is some method assignable to Func<Exception, FaultException>
). Is there any pattern for passing this type of parameter to the aspect? Many types can be passed into aspects. Is this a common problem?
If there happens to be a better way to accomplish this, I would appreciate the advice.