5

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?

matthewbaskey
  • 1,027
  • 2
  • 17
  • 40

2 Answers2

4

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

Gustavo Armenta
  • 1,525
  • 12
  • 14
  • 1
    I think the business logic actually executes in a separate AppDomain. How would I setup a SignalR client in the MVC app? Thanks – matthewbaskey Aug 08 '13 at 19:51
  • can you provide some sample? – Claudio Santos Oct 07 '13 at 12:54
  • Sample inside same process: http://www.asp.net/signalr/overview/hubs-api/hubs-api-guide-server#callfromoutsidehub Sample of a C# client when things run on different processes: http://www.asp.net/signalr/overview/hubs-api/hubs-api-guide-net-client – Gustavo Armenta Oct 08 '13 at 02:16
1

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");

Matt Watson
  • 980
  • 7
  • 10