Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
ASP.NET Core 3 and React

You're reading from   ASP.NET Core 3 and React Hands-On full stack web development using ASP.NET Core, React, and TypeScript 3

Arrow left icon
Product type Paperback
Published in Dec 2019
Publisher Packt
ISBN-13 9781789950229
Length 598 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Jason Watmore Jason Watmore
Author Profile Icon Jason Watmore
Jason Watmore
Carl Rippon Carl Rippon
Author Profile Icon Carl Rippon
Carl Rippon
Arrow right icon
View More author details
Toc

Table of Contents (22) Chapters Close

Preface 1. Section 1: Getting Started FREE CHAPTER
2. Understanding the ASP.NET Core React Template 3. Creating Decoupled React and ASP.NET Core Apps 4. Section 2: Building a Frontend with React and TypeScript
5. Getting Started with React and TypeScript 6. Routing with React Router 7. Working with Forms 8. Managing State with Redux 9. Section 3: Building an ASP.NET Core Backend
10. Interacting with the Database with Dapper 11. Creating REST API Endpoints 12. Creating a Real-Time API with SignalR 13. Improving Performance and Scalability 14. Securing the Backend 15. Interacting with RESTful APIs 16. Section 4: Moving into Production
17. Adding Automated Tests 18. Configuring and Deploying to Azure 19. Implementing CI and CD with Azure DevOps 20. Assessments 21. Other Books You May Enjoy

Pushing data to SignalR clients from an API controller

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:

  1. We'll start by referencing SignalR and our SignalR hub with using statements:
using Microsoft.AspNetCore.SignalR;
using QandA.Hubs;
  1. We are going to inject the context of the hub into the API controller using dependency injection:
[Route("api/[controller]")]
[ApiController]
public class QuestionsController...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at ₹800/month. Cancel anytime