How do I get a reference to a Hub? #182
Comments
What exactly are you trying to do here? |
@mikaelm12 I'm trying to get some data from an Akka.NET actor to a SignalR hub, but I don't know how to get a reference to the hub.... Specifically, trying to port this |
Hubs aren't really meant to be called except from a client, you get away with it in your project by using I would recommend creating and injecting a class with shared logic for use in your Arbitrary example (not tested)
|
@BrennanConroy Thanks, that looks like a better strategy. I'm just not sure how to get the reference to inject into the IHubContext if GlobalHost is no longer available.... |
You should be able to resolve the IHubContext without doing any extra registration; SignalR does the necessary registration when calling |
@mikebridge You take it as a constructor argument to your registered service. |
In this screencast I setup an mvc controller, when posted to, we broadcast to all connected clients, in our specific case, it's angular apps running on a seperate host, so it involves CORS as well. https://www.towfeek.se/2017/09/16/consuming-signalr-for-aspnet-core-from-angular/ Hope it helps, cheers! |
Anybody have a non-arbitrary, tested example? I've added something similar to this but now my App cannot connect to the server (works before I add the ctor to the hub). |
Figured it out, the Hub constructor needed to take the context not the methods.
|
In the old SignalR I could get a reference to a hub via something like this:
Is there a way to find a hub in the current version (0.2.0)?
The text was updated successfully, but these errors were encountered: