From the course: Learning SignalR with ASP.NET Core

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Add persistence to SignalR

Add persistence to SignalR

From the course: Learning SignalR with ASP.NET Core

Start my 1-month free trial

Add persistence to SignalR

- [Instructor] Earlier in the course, I mentioned that SignalR only helps you send and receive messages, and doesn't include any notion of saving or persisting messages. Sometimes, having truly ephemeral messages is fine, but in many applications, you'll want to save messageS in a database, or use them in a piece of business logic. You can think of the SignalR hub as a specialized controller in ASP.NET Core. When requests come into the hub, you can talk to a data store, or maybe call some business logic that's encapsulated in a service. Business logic code can also use the hub the other way around, to broadcast messages to clients. As a result, adding persistence to SignalR looks exactly like adding database calls to an ASP.NET Core controller. It's not something the hub does directly, but you can inject a DbContext or a service class into the hub to do the work. It turns out that we've already done that by injecting the iChatroom service in the chat hub. This service class is already…

Contents