Is there a way to handle the exception thrown by the WCF service constructor when this constructor accepts the dependency, and is it creating dependencies of the IoC container (in this case AutoFac) that throws the exception ?
Consider a WCF service with the following constructor:
public InformationService(IInformationRetriever informationRetriever) { _informationRetriever = informationRetriever; }
The service uses AutoFac WcfIntegration and AutofacWebServiceHostFactory
(this is usually a RESTful service).
Dependencies are recorded in the global.asax.cs service, that is:
builder.RegisterType<InformationRetriever>() .As<IInformationRetriever>()
The InformationRetriever
implementation now performs some checks in its constructor to ensure that it can do its job. When it detects a problem in this phase, it throws an exception.
However, I do not want the calling service object to receive an AutoFac exception:
An exception was thrown while invoking the constructor ... on type InformationRetriever
In fact, I'm trying to check:
This works InformationService
When I call the GetSomeInformation () method
And Unable to instantiate InformationRetriever
Then I want to return a welcome error message
And write down the actual exception
Is this a problem for my design, or is there a known pattern for overcoming or preventing this problem?
I hunted around and could not find any information about this type of problem.