How do you share state between two components that are not in a parent-child relationship?

Last updated 5 July 2026

  • Create a state container service holding the data plus an event Action raised on change, registered with AddScoped or AddSingleton.

  • Both components @inject it: one writes, the other subscribes in OnInitialized and calls StateHasChanged() in the handler.

  • Unsubscribe in Dispose to avoid memory leaks.

  • https://learn.microsoft.com/en-us/aspnet/core/blazor/state-management/?view=aspnetcore-10.0
  • https://learn.microsoft.com/en-us/answers/questions/1377680/blazor-default-template-application-issue
  • https://learn.microsoft.com/en-us/aspnet/core/blazor/components/rendering?view=aspnetcore-10.0
  • https://medium.com/@Adem_Korkmaz/blazor-and-net-8-a-complete-guide-8a8886f02eef
  • https://www.syncfusion.com/blogs/post/master-state-management-in-blazor
All Blazor interview questions