diff --git a/aspnetcore/blazor/components/cascading-values-and-parameters.md b/aspnetcore/blazor/components/cascading-values-and-parameters.md index 6eb53c000552..0124245cde63 100644 --- a/aspnetcore/blazor/components/cascading-values-and-parameters.md +++ b/aspnetcore/blazor/components/cascading-values-and-parameters.md @@ -33,7 +33,7 @@ The following class is used in this section's examples. :::code language="csharp" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/Dalek.cs"::: -The following registrations are made in the app's `Program` file: +The following registrations are made in the app's `Program` file with : * `Dalek` with a property value for `Units` is registered as a fixed cascading value. * A second `Dalek` registration with a different property value for `Units` is named "`AlphaGroup`". @@ -60,6 +60,13 @@ builder.Services.AddCascadingValue(sp => }); ``` +> [!WARNING] +> Registering a component type as a root-level cascading value doesn't register additional services for the type or permit service activation in the component. +> +> Treat required services separately from cascading values, registering them separately from the cascaded type. +> +> Avoid using to register a component type as a cascading value. Instead, wrap the `...` in the `Routes` component (`Components/Routes.razor`) with the component and adopt global interactive server-side rendering (interactive SSR). For an example, see the [`CascadingValue` component](#cascadingvalue-component) section. + :::moniker-end ## `CascadingValue` component @@ -468,3 +475,8 @@ The following `ExampleTabSet` component uses the `TabSet` component, which conta private bool showThirdTab; } ``` + +## Additional resources + +* [Generic type support: Explicit generic types based on ancestor components](xref:blazor/components/generic-type-support#explicit-generic-types-based-on-ancestor-components) +* [State management: Factor out the state preservation to a common location](xref:blazor/state-management?pivots=server#factor-out-the-state-preservation-to-a-common-location) diff --git a/aspnetcore/blazor/state-management.md b/aspnetcore/blazor/state-management.md index 0a6b7aa5cc6b..7a2165c61752 100644 --- a/aspnetcore/blazor/state-management.md +++ b/aspnetcore/blazor/state-management.md @@ -493,8 +493,26 @@ else The `CounterStateProvider` component handles the loading phase by not rendering its child content until state loading is complete. +:::moniker range=">= aspnetcore-8.0" + +To make the state accessible to all components in an app, wrap the `CounterStateProvider` component around the (`...`) in the `Routes` component with global interactive server-side rendering (interactive SSR). + +In the `App` component (`Components/App.razor`): + +```razor + +``` + +In the `Routes` component (`Components/Routes.razor`): + +:::moniker-end + +:::moniker range="< aspnetcore-8.0" + To use the `CounterStateProvider` component, wrap an instance of the component around any other component that requires access to the counter state. To make the state accessible to all components in an app, wrap the `CounterStateProvider` component around the in the `App` component (`App.razor`): +:::moniker-end + ```razor @@ -773,8 +791,6 @@ When implementing custom state storage, a useful approach is to adopt [cascading * To consume state across many components. * If there's just one top-level state object to persist. -For additional discussion and example approaches, see [Blazor: In-memory state container as cascading parameter (dotnet/AspNetCore.Docs #27296)](https://github.com/dotnet/AspNetCore.Docs/issues/27296). - ## Troubleshoot In a custom state management service, a callback invoked outside of Blazor's synchronization context must wrap the logic of the callback in to move it onto the renderer's synchronization context.