--- no-loc: [Kestrel, appsettings.json, "ASP.NET Core Identity", cookie, Cookie, Blazor, "Blazor Server", "Blazor WebAssembly", "Identity", "Let's Encrypt", Razor, SignalR] --- Nested components typically bind data using *chained bind* as described in . Nested and un-nested components can share access to data using a registered in-memory state container. A custom state container class can use an assignable to notify components in different parts of the app of state changes. In the following example: * A pair of components uses a state container to track a property. * One component in the following example is nested in the other component, but nesting isn't required for this approach to work. `StateContainer.cs`: ```csharp using System; public class StateContainer { private string savedString; public string Property { get => savedString; set { savedString = value; NotifyStateChanged(); } } public event Action OnChange; private void NotifyStateChanged() => OnChange?.Invoke(); } ``` In `Program.Main` (Blazor WebAssembly): ```csharp builder.Services.AddSingleton(); ``` In `Startup.ConfigureServices` (Blazor Server): ```csharp services.AddScoped(); ``` `Shared/Nested.razor`: ```razor @inject StateContainer StateContainer @implements IDisposable

Nested component

Nested component Property: @StateContainer.Property

@code { protected override void OnInitialized() { StateContainer.OnChange += StateHasChanged; } private void ChangePropertyValue() { StateContainer.Property = $"New value set in the Nested component: {DateTime.Now}"; } public void Dispose() { StateContainer.OnChange -= StateHasChanged; } } ``` `Pages/StateContainer.razor`: ```razor @page "/state-container" @inject StateContainer StateContainer @implements IDisposable

State Container component

State Container component Property: @StateContainer.Property

@code { protected override void OnInitialized() { StateContainer.OnChange += StateHasChanged; } private void ChangePropertyValue() { StateContainer.Property = $"New value set in the State Container component: {DateTime.Now}"; } public void Dispose() { StateContainer.OnChange -= StateHasChanged; } } ``` The preceding components implement , and the `OnChange` delegates are unsubscribed in the `Dispose` methods, which are called by the framework when the components are disposed. For more information, see .