I'm wondering if it's possible to Cast the result of
var hub = GlobalHost.ConnectionManager.GetHubContext<ChatHub>();
To my actual ChatHub class.
Because GlobalHost.ConnectionManager.GetHubContext<ChatHub>() as ChatHub
fails
On my ChatHub class I have a method UpdateTime():
public void SendTimeUpdate(DateTime time, string auth)
{
Clients.All.UpdateTime(time, auth);
}
And I want to call it from my other class. Since I can't cast to ChatHub and invoke the SendUpdate I have to go:
GlobalHost.ConnectionManager.GetHubContext<ChatHub>().Clients.All.UpdateTime(time, auth);
But if I go this road, the method SendTimeUpdate isn't added in the proxy script /signalr/hubs
Is there a solution for this problem? I want to get the typed Hub instance and not call stuff directly on the Clients property of the IHubContext.
No you cannot cast the result of ....GetHubContext<....
to your hub class. Sorry :(.
The GetHubContext approach returns an IHubContext
when a Hub is only an IHub
.
If you'd like to centralize the logic just make a method that you can call into from your hub and from your external service.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With