Building a live communication service using SignalR
The SignalR server library is included in ASP.NET Core. But the JavaScript client library is not automatically included in the project. We will use the Library Manager CLI to get the client library from unpkg, a content delivery network (CDN) that can deliver anything found in Node Package Manager.
Let’s add a SignalR server-side hub and client-side JavaScript to an ASP.NET Core MVC project to implement a chat feature that allows visitors to send messages to:
- Everyone currently using the website
- Dynamically defined groups
- A single specified user
Good Practice: In a production solution, it would be better to host the SignalR hub in a separate web project so that it can be hosted and scaled independently from the rest of the website. Live communication can often put excessive load on a website.
Defining some shared models
First, we will define two shared models that can...