Given a \'default\' Blazor app - created using the Visual Studio 2019 Blazor server template. How do you create a GLOBAL object that is acc
Communication between components can be implemented in three ways, depending on your requirements and needs.
A parent component can communicate with its child component by passing component parameters and raising events to let the parent that something has happened, and vice versa.
You can enable the CascadingValue feature to pass a value to all children down the stream, who define a property of CascadingParameter. The cascading value may be a simple string, but it can also be a complete component. This is achieved by setting the Value attribute of CascadingValue with the key word this from within the component you want to pass reference, like this:
@ChildContent
I don't like using this feature. Actually, I never use it. It is claimed it's use can be problematic, etc. However, it is a legitimate part of Blazor, and there is no reason not to use it if you like...
Given a 'default' Blazor app - created using the Visual Studio 2019 Blazor server template. How do you create a GLOBAL object that is accessible from all the razor pages and components.
You should implement a service. See number 3.
Create a Static Class ?
No, no static classes. Create a service
What is the recommended approach in Blazor?
It all depends on your needs and requirements...
How would you make the 'Current Count ' value - visible and 'dynamically' updated on the MainLayout, NavMenu, Index pages?
Only by creating a service that allow you to pass the current count from a given location, and pass it to other components such as MainLayout, NavMenu, Index pages.
Note: I've answered such questions in details with working code. I've no idea of their location (400 answers so far), but you can go to my profile page and look for them.
Hope this helps...