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.
var hub = hubManager.ResolveHub(nameof(AdminHub)) as AdminHub;