
The goal – how to create a basic forum discussion site
Forums have been around since the dawn of computing, taking on many forms: bulletin board systems, user groups, and also web-based forums on different sites. In this chapter, we'll build our own forum and light it up with SignalR, improving the overall user experience and also scalability of the solution. We'll use the top-level abstraction within SignalR called a hub. The hub enables us to expose methods from the server directly to the client and also makes it possible to call functions on the client side from the server directly.
By the end of the chapter, you'll understand the basics of SignalR and how to use the top-level abstraction: hub. Also, you will briefly look at what MVC gives you in combination with Entity Framework.
So, let's just jump straight into it!
Hub
At the core level of SignalR sits something called a PersistentConnection
class; hubs build on top of this. We won't be covering PersistentConnection
as it is far more convenient to be working with the hub. In my opinion, a hub is the preferred abstraction to use; most applications really don't need to go any lower than this. It provides functionality to define functionality on the server in a C# class, much like an MVC or a Web API controller with the exception of it being persistently connected, leaving it possible to also call functionality on the client as well. The clients consume the hub and can directly call the methods on them. However, these clients can also register the client functions it responds to and create a subscription from the client that makes it respond to what it registered when the server calls it.