Overview

Application state for the current-running instance of the application can be saved and shared between Components.

Create some class to store state:

public class ApplicationState
{
    // create a property/field for each piece of data to be stored
    public int NumberOfMessages { get; set; } = 0;
}

Add the instance to DI:

builder.Services.AddScoped<ApplicationState>();

Inject it and use it:

[Inject]
public ApplicationState? ApplicationState { get; set; }

int a = ApplicationState.NumberOfMessages;