Last post Jun 03, 2014 07:10 PM by halter73
May 29, 2014 06:48 AM|CristianSM|LINK
I'm new to signalR. What I'd like to do if it's possible is to inject an instance of a hub class into a web api controller. I've tried doing it and always get the error that my hub can't be created outside the signalR pipeline. The workaround that I've found
is obtaining the IHubContext and also found a controller class that extends WebApiController by adding IHubContext property, but I'd like to know if it's possible to fully decouple the web api controller from signalR.
public interface ISomeNotifier
void Notify(SomeEvent someEvent);
public class SomeHub : Hub, ISomeNotifier
public void Notify(SomeEvent someEvent)
public class MyController : ApiController
public MyController(ISomeNotifier notifier)
//initialize private var
Jun 03, 2014 07:10 PM|halter73|LINK
While you may not be able to inject a working hub itself, you can create an IHubContext which will allow you to message the clients connected to the specified Hub.
You can learn more about create and use an IHubContext from
SignalR Hubs API Guide.