Application State with Blazor: Carl Franklin's Blazor Train ep 15

DevExpress · 11K views · 2020 · 18:56

Open on YouTube

Web developmentSoftware architecture & designtutorial

Why Stack Overflow recommends it

Stack Overflow users link it when answering Blazor questions about sharing data between pages or components and pointing to the AppState or state container pattern.

Recommended by 2 people across 3 different months, 2020 to 2021.

What it is

Carl Franklin, in episode 15 of his Blazor Train series for DevExpress, shows how to keep application data outside components and pages in a shared state object. He also demonstrates cross-component change notifications so that UI updates when the shared state changes. Sample code is provided on GitHub.

What people said

Recommends Kyle Cintron · 2021-06 · Stack Overflow · on “How to pass the value entered in a text box from a modal window to another component using Blazor server?”

There are a few different ways you can do this depending on your needs: Cascading Parameters: A good video for the basics of it - [LINK] An AppState approach: A good video for it covering two different ways: [this video] Or you can pass it in as a parameter to the component: [LINK] (scroll down to the 'Binding with component parameters' section I included videos as I believe they are more helpful but let me know if it is not clear.

Recommends Kyle Cintron · 2021-08 · Stack Overflow · on “What's the best way to handle session in Blazor (that ISN'T dependent on client)?”

There are a few different ways you can do this depending on your needs: Cascading Parameters: A good video for the basics of it - [LINK] An AppState approach: A good video for it covering two different ways: [this video] The main issue with both of these is they are still by session and will be gone on refresh or a new tab. The only other solution I know of is by using redis, this would keep the data as long as you want to keep it for but it would not be in blazor. Good video of it: [LINK]

Recommends Nicola Biada · 2021-09 · Stack Overflow · on “Blazor Webassembly navigating back and forth initialize”

Use a state manager (with a storage or not, is the same) Look at Carl Franklin Blazor Train episode about application state [this video] and Microsoft official documentation [LINK] The page is the same (like said Shaun), in case you need control on this I think you need to use OnAfterRender, and obviously, see Shaun, the OnParameter

Recommends Kyle Cintron · 2021-09 · Stack Overflow · on “How to send information from previous page to current page in Blazor?”

There are several ways to accomplish this depending on how you want to implement this and the structure of the project. Using cascading parameters [LINK] this will work if these other pages are actually components of one page. Using browser storage either local [LINK] or session [LINK] storage - local being "permanent" until manually deleted and session being only for that current session. Could potentially require you to continuously send data from the server to the browser just to receive that data back on the next page. An AppState [this video] (Youtube video) approach - essentially each client per session will have an object in MainLayout that is passed as a cascading parameter into all pages

Cites Brian MacKay · 2020-10 · Stack Overflow · on “How can I modify the layout from a blazor page?”

State Container Pattern I ended up solving this using the State Container pattern. If you don't know what that is, these links are helpful: [LINK] (last section) [this video] (deeper dive with additional options) Overview I made a Scoped service just for handling nav. It's injected into my Navbar component, where it is used to manage breadcrumbs. The nav service also has an event that refreshes the navbar UI whenever the breadcrumbs change. Nav options can be configured on a page-by-page basis. To make things easier for myself, I also created a base page that inherits from ComponentBase. I've simplified my code somewhat. In my actual project I am managing more than just breadcrumbs here. MainLayo