When is the SignalR hub constructor called?

Tim picture Tim · Jul 29, 2013 · Viewed 7k times · Source

I'm trying to debug a SignalR hub and noticed that the constructor is getting called multiple times, even with a single client. Is this the expected behaviour? I was expecting the constructor to be called only once for class initialisation, but I'm hitting my breakpoint multiple times.

Answer

Incognito picture Incognito · Jul 29, 2013

In SignalR Hub instance will be created per each request. So it does't matter if there is only one client or more. In fact Hub is an abstraction over PersistentConnection, if you want more precise control over the things happening behind the scene you can use PersistentConnection. Check here : https://github.com/SignalR/SignalR/wiki/PersistentConnection