In a Blazor WebAssembly site, suppose I have a class
public class State : IState
{
public bool ShowEasterEggs { get; set; } = false;
}
And I properly register it in my client's Program.cs: builder.Services.AddSingleton<IState, State>();
And I properly inject this into a component:
@inject IState State
@if (State.ShowEasterEggs)
{
<span>EASTER EGGS SHOWN</span>
}
And in some other component, I enable a change to it:
@inject IState State
<input type="checkbox" @bind="State.ShowEasterEggs"/>Show Easter Eggs
I expect that a change to State.ShowEasterEggs from the second component would be detected and any instance of the first component would update automatically. But I find that I need to do some other interaction--changing other values in the first component's parent, to see the change in the first component's instance.
So how does this work, how should it work, and how can I get changes to injected objects to cause an update?