bruceiow
bruceiow

Reputation: 327

how to use signalr across multiple projects

We have a customer waiting system where a customer can report in and sit and wait. Our advisers have another part of the system where they can see the queue and pick a customer and call them up.

In our solution we have a project for the customer sign in screen. The touch screen project is mvc and has a controller action to raise a new ticket to the database.

We then have another project that is for our advisers screens. This looks at the same database and again is MVC. There is a controller action to get latest tickets from the DB.

What I want to do is use signalr to inspect when a ticket is created by the touch screen and then report that back to the connected client machines in the advisers project.

How do I structure that? Do I create a new project called signalr that has references to both projects or do I need to put my hubs etc in one or other of the existing projects? Also is this even possible across multiple projects?

I looked in to sql dependency to track changes, but we are using EF ORM and I couldn't wire that up.

many thanks

Upvotes: 1

Views: 3609

Answers (3)

Chad Hedgcock
Chad Hedgcock

Reputation: 11765

Adding my own solution here because the current answers don't really answer how to approach setting up SignalR across projects.

I essentially had a console app that needed to talk to an MVC app, so I was confused about where to put the hub. The console can't be the hub because it doesn't have an http address that the MVC project's JavaScript can point to. The MVC project couldn't be the hub because then it would have to be referenced by the console app, which coupled the two too tightly for my liking.

The solution was to use a 3rd web api project as the hub. Example from Brad Wilson on how to do that here.I could point my JavaScript there as explained here, and the console app could make POST requests to the controller there that sends messages to the hub.

Upvotes: 0

Killnine
Killnine

Reputation: 5880

@Dani: Those are excellent resources.

I believe what you are doing is a very plausible use case for SignalR.

To answer your first question: You don't create a SIgnalR project, per se. You add a reference to SignalR in an existing project. Therefore, it's possible to use SignalR across multiple projects.

Your project where tickets are created would probably have the full SignalR reference because it would be the one to fire off a 'broadcast' to the Advisors that are currently connected. However, the Advisors project would only need a reference to the SignalR.Client because all it would need is to connect to the SignalR hub and await new tickets.

Upvotes: 0

Related Questions