Arguably the most valuable piece of our real-time API is pushing new answers to subscribed clients. In this section, we are going to learn how to do this. If we think about it, the ideal place to do this is in the questions API controller, which is where an answer is posted. So, when an answer is posted, we want SignalR to push the updated question with the saved answer to all the clients that are subscribed to the question. Let's implement this by carrying out the following steps in QuestionsController.cs:
- We'll start by referencing SignalR and our SignalR hub with using statements:
using Microsoft.AspNetCore.SignalR;
using QandA.Hubs;
- We are going to inject the context of the hub into the API controller using dependency injection:
[Route("api/[controller]")]
[ApiController]
public class QuestionsController...