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, 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 BlazorWebAssembly runs inside the web browser and doesn't have a connection to the server or other users.
To show how in-memory state works, we will do something that might seem like a bit of overkill for a blog, but it will be kinda cool to see. When we edit our blog post, we will make sure to 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 hosting. Let's start with Blazor Server.