SignalR Hub subclass

We now need to create the SignalR Hub. To do this, perform the following steps:

  1. Add a class to your project to handle the server-side of the chat. We'll call it Chat:

This will need to be a subclass of the SignalR Hub class. Make sure to add the using directive for Micosoft.AspNetCore.SignalR. Visual Studio's Quick Actions works well for this:

  1. Now add a Task method to the class to handle the sending of the messages:
 public Task Send(string sender, string message) { return Clients.All.InvokeAsync("UpdateChat", sender, ...

Get C# 7 and .NET Core 2.0 Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.