0

Is there anyway to handle exceptions which are thrown in Hub constructor methods? Currently there is only HubPipelineModule which can handles only calling methods related exceptions but not constructor exception.

Assume in Hub constructor I get the "Database connection error". Now I want to show the end user a proper message.

I checked the following links but they are not helpful in this case :

Community
  • 1
  • 1
Mahmoud Moravej
  • 8,705
  • 6
  • 46
  • 65
  • Sounds like your using your hub in a wrong way if you are doing database calls from its constructor. The hub you have no logic besides handling calls from the client. – Anders Nov 18 '14 at 08:20
  • No, I just do some preparation. This preparation is not related to user calls. – Mahmoud Moravej Nov 18 '14 at 14:43
  • I think the HUB should only be a thin bridge between the clien calls and your backend. Plus its recontructed for each request so you cant keep any data there anyway. – Anders Nov 18 '14 at 15:42
  • I know this. I only check some little codes there. Now the main problem is catching and handling exception in a right way at hub construction – Mahmoud Moravej Nov 18 '14 at 19:10

1 Answers1

1

Your best bet for handling exceptions thrown from a Hub constructor is probably by providing your own IHubActivator.

Here is an example of how you can replace SignalR's IHubActivator. In that example the purpose for replacing IHubActivator was to use Simple Injector to activate hubs, but the same principle applies if you just want to handle/log any exceptions thrown during Hub construction.

Community
  • 1
  • 1
halter73
  • 15,059
  • 3
  • 49
  • 60