Skip to content

Latest commit

 

History

History
54 lines (35 loc) · 1.8 KB

File metadata and controls

54 lines (35 loc) · 1.8 KB

##HubConnectionManager##

###Overview###

HubConnectionManager is a simple wrapper class around the HubConnection class SignalR uses to establish a connection with a server.

###NuGet Installation### > Install-Package HubConnectionManager

https://www.nuget.org/packages/HubConnectionManager/

###Background###

Prior to HubConnectionManager, if I happened to launch a client applicaiton when its corresponding SignalR service was unavailable, I'd have to restart the whole application for it to recover. Now, with HubConnectionManager, I can ensure that the client will attempt to re-establish a connection with the server. And it works!

Furthermore, wrapping the HubConnection in an IHubConnectionManager interface means that mocking connection state is easy. Hooray for comprehensive unit testing!

###Usage###

  1. Create an instance of HubConnectionManager through the static GetHubConnectionManager method, providing the url of your SignalR endpoint:
HubConnectionManager connectionManager = HubConnectionManager.GetHubConnectionManager("http://localhost:6789");
  1. Create you IHubProxy via the CreateHubProxy method, passing in the name of your Hub:
IHubProxy clientProxy = connectionManager.CreateHubProxy("ClientHub");
  1. Initialize the Manager via Initialize() method:
connectionManager.Initialize();

That's it! As long as you have a reference to the HubConnectionManager like you'd have a reference to your HubConnection in the past, it should work just the same.

###Additional Functionality###

I also expose many of the events and properties of HubConnection:

####Events####

  • Error
  • Received
  • Closed
  • Reconnecting
  • Reconnected
  • ConnectionSlow
  • StateChanged

####Properties####

  • State