I'm making an assumption that by "Classes" you mean "Blazor Components".
If so, a simple way is via a Scoped Data Service through Dependency Injection.
Your Service:
public class MyDataService
{
public int MyInt { get; set; }
}
Add to the Services container in Program:
builder.Services.AddSingleton<WeatherForecastService>();
// The service
builder.Services.AddScoped<MyDataService>();
Any Component/Page can set or consume it.
@page "/"
@inject MyDataService DataService
<PageTitle>Index</PageTitle>
<h1>Hello, world!</h1>
Welcome to your new app.
<SurveyPrompt Title="How is Blazor working for you?" />
@code {
private int myInt = 0;
protected override void OnInitialized()
{
this.DataService.MyInt = 2;
//...
myInt = this.DataService.MyInt;
}
}