I have a class with some currentstate
parameters (instead of session variables)
In program.cs
:
builder.Services.AddScoped<CurrentState>();
Can I inject this CurrentState
and read / update parameters at runtime?
When I tried this every component that inject this with @inject CurrentState currentState
, every currentState = null
and get a new hashcode (currentState.GetHashCode()
)
I’ve read an article somewhere that you can do this but can’t find it again. Is it totally wrong and I must use sessions or is there a way to use this ang get same instance of CurrentState
in all components?
Found an article similiar : https://wellsb.com/csharp/aspnet/blazor-singleton-pass-data-between-pages#google_vignette
I use serverside so can’t use .Singleton. But it seams like I get a completely new instance on every injection?
3