Reputation: 4227
I am using Caliburn (an MVVM framework) in combination with Castle Windsor and the WCF Facility.
My Presenter class has a constructor dependency which is actually a WCF contract that will be supplied by the Windsor container.
What I would like to achieve, is if the endpoint is not found, that presenter obviously cannot be displayed, I would like a view to be displayed explaining "A network service required to display this form cannot be located. Please try again later.".
What would be the best way to hook into Castle/Caliburn to centralise this code, so that the same error view is shown, no matter where in the application a presenter failed to be resolved due to the EndpointNotFoundException?
Any ideas?
I want to avoid having to put a 'try/catch endpoint-not-found' around all presenter resolutions JUST INCASE IT DEPENDS ON WCF....
Upvotes: 1
Views: 330
Reputation: 1468
A quick (but a little dirty, in my opinion) solution could be to decorate with a Rescue filter all the calling presenters, thus allowing a rescue method to intercept that particular exception. Applying the filter to all presenters could be relatively easy if you have a common base class (you just have to apply it to the common ancestor), otherwise you either have to apply the filter manually or customize the routed messaging stack (which is a bit harder).
You can also build some sort of "lazy instantiation" using a proxy instead of the real service. In this proxy you can resolve the real WCF service under a try/catch handler, opening an informative window if internal resolution fails. I don't like too much this solution because you have no clues on the invocation context, so you may show the info to the user even when it would be inappropriate.
I also would like to point out an elegant way to handle network outage, automatically disabling the launch point of the action opening the presenter needing a network connection.
Upvotes: 1