Using an in-memory state container service
When it comes to in-memory state containers, we simply use dependency injection to keep the instance of the service in memory for the predetermined time (scoped, singleton, or transient).
In Chapter 4, Understanding Basic Blazor Components, we discussed how the scope of dependency injections differs from Blazor Server and Blazor WebAssembly. The big difference for us in this section is the fact that Blazor WebAssembly runs inside the web browser and doesn’t have a connection to the server or other users.
To show how the in-memory state works, we will do something that might seem a bit overkill for a blog but it will be cool to see. When we edit our blog post, we will update all the web browsers connected to our blog in real time (I did say overkill).
We will have to implement that a bit differently, depending on the host. Let’s start with Blazor Server.
Implementing real-time updates on Blazor Server
The...