Late binding in SignalR

Once in a while there’s a need to add a callback to signalR after the hubs/connections have been started. Out of the box – you can’t, though its pretty easy to add.

Here’s a solution we’re using for one of internal projects, which basically wraps the hub, and allows to (optionally) add the callbacks at any time: Continue reading “Late binding in SignalR”

SignalR: How to get a current Hub instance

Once in a while, it’s helpful to call a Hub method from a controller, responding to some server side event.  Took me a while to figure this out, but in the end, this is easy.

DefaultHubManager hubManager = new DefaultHubManager(GlobalHost.DependencyResolver);
var hub = hubManager.ResolveHub("AdminHub"as AdminHub;
 
hub.SendMessage("woohoo");

One thing I don’t like is having to pass a hub name as a string – I think they should’ve asked for type. Easy enough to fix with a helper or extension method.