Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call SignalR Hub from Backend Business Layer

I have an MVC website sitting onto of some fairly hefty business objects. My MVC Controllers call Manager objects which conducts and delegates work off to other sets of objects.

Basically the code is deep server side, while a Hub in a way is just like a Controller in that it is fairly close to the client side.

Is there a way to execute SignalR methods based on a reference to the Hub passed to these Manager objects?

like image 586
matthewbaskey Avatar asked Oct 04 '22 07:10

matthewbaskey


2 Answers

If your MVC and SignalR services are running on the same process, you can call GlobalHost.ConnectionManager.GetHubContext("MyHub");

It they are on separate processes, then you need to create a SignalR client in your MVC app

like image 191
Gustavo Armenta Avatar answered Oct 07 '22 16:10

Gustavo Armenta


Well all of the clients will connect to your web app and persist the connections there. From a separate back end program you can just call a web service in your web app and that web service can post the message on the same SignalR hub in your web project. Your back end app can't connect to the SignalR hub directly. It all flows through a single point, being your web app.

If you are just talking about a shared class library in the same web app, you should be able to pass the hub object to the other class as the other person answered: GlobalHost.ConnectionManager.GetHubContext("MyHub");

like image 28
Matt Watson Avatar answered Oct 07 '22 15:10

Matt Watson