The correct way is to actually create the hub context. How and where you do that is up to you, here are two approachs:
-
Create a static method in your hub (doesn’t have to be in your hub, could actually be anywhere) and then you can just call it via
AdminHub.SendMessage("wooo")
public static void SendMessage(string msg) { var hubContext = GlobalHost.ConnectionManager.GetHubContext<AdminHub>(); hubContext.Clients.All.foo(msg); }
-
Avoid the static method all together and just send directly to the hubs clients
var hubContext = GlobalHost.ConnectionManager.GetHubContext<AdminHub>(); hubContext.Clients.All.foo(msg);