Skip to content

SignalR extension to help retry connecting to server if initialization fails on startup. Also provides more convenient unit testing interface.

Notifications You must be signed in to change notification settings

killnine/HubConnectionManager

Repository files navigation

##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

About

SignalR extension to help retry connecting to server if initialization fails on startup. Also provides more convenient unit testing interface.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published