How to structure a Blazor Server app in ASP.NET 8. #49493
Unanswered
marinasundstrom
asked this question in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have been exploring the upcoming version of Blazor. Because of that I have put together an example showing how to structure a Blazor "United" Server app with server-side rendered pages that are hosting WebAssembly components with pre-rendering enabled.
I think that this might be of use and help to others.
GitHub: https://github.com/marinasundstrom/Blazor8Test
Hosted at: https://blazor8app.graypebble-0c46426e.westus2.azurecontainerapps.io/
Purpose
To demonstrate:
Structure
The solution looks like this:
Server-side rendering (SSR)
The main part of the ite is server-side rendered - with interactive components on certain pages.
Both Server components and WebAssembly components.
Pre-rendering is enabled.
Data service: IWeatherForecastService
The
WeatherForecastService
interface is consumed by theShowData
andFetchData
pagecomponents. It has two implementations one for server which acts as the data source in the server, and another implementation for the client that invokes a WebAPI.When a component is being pre-rendered then it is within the context of the server, and thus uses the server implementation.
Since I re-designed the interface, the client-side
FetchData
page has become superfluous. It used to just have a plainHttpClient
for a brief time.RenderingContext class
This object exposes properties that indicate what rendering context code is running in, and whether it is doing pre-rendering.
Beta Was this translation helpful? Give feedback.
All reactions