Blazor app models


Blazor seamlessly operates on web browsers using WebAssembly and extends its capabilities to Android, iOS, Windows, and macOS through the .NET runtime, with full access to native platform features and third-party libraries developed in Swift, Objective-C, Kotlin, and Java.
Notably, Blazor offers pre-rendering in order to be seo friendly.

Blazor Server
With the Blazor Server hosting model, the app is executed on the server from within an ASP.NET Core app. UI updates, event handling, and JavaScript calls are handled over a SignalR connection using the WebSockets protocol.
To use to Blazor Server:
  1. Open the file Core/Services/AppRenderMode.cs and change the Current field to BlazorServer.

  2. public static IComponentRenderMode Current => BlazorServer
  3. Set the "Server" project as the startup project.
  4. Run the application.
  5. When the browser opens, remove "swagger/index.html" from the URL address bar to view the app UI instead of the swagger UI.
Blazor WebAssembly
Blazor WebAssembly (WASM) apps run client-side in the browser on a WebAssembly-based .NET runtime. The Blazor app, its dependencies, and the .NET runtime are downloaded to the browser. The app is executed directly on the browser UI thread. UI updates and event handling occur within the same process.
To use to Blazor WebAssembly:
  1. Open the file Core/Services/AppRenderMode.cs and change the Current field to BlazorWebAssembly.

  2. public static IComponentRenderMode Current => BlazorWebAssembly
  3. Set the "Server" project as the startup project.
  4. Select Boilerplate.Server-BlazorWebAssembly launchSettings profile instead of Boilerplate.Server-Swagger
  5. Blazor WASM target
  6. Run the application.
  7. When the browser opens, remove "swagger/index.html" from the URL address bar to view the app UI instead of the swagger UI.
Blazor Auto
Blazor seamlessly combines Blazor Server and WebAssembly. This approach enhances user interaction initially through Blazor Server, while simultaneously downloading Blazor WebAssembly for subsequent visits, reducing server load.
To use to Blazor Auto:
  1. Open the file Core/Services/AppRenderMode.cs and change the Current field to Auto.

  2. public static IComponentRenderMode Current => Auto
  3. Set the "Server" project as the startup project.
  4. Select Boilerplate.Server-Swagger launchSettings profile instead of Boilerplate.Server-BlazorWebAssembly.
  5. Run the application.
  6. When the browser opens, remove "swagger/index.html" from the URL address bar to view the app UI instead of the swagger UI.
Note: The provided code employs Blazor Server during development for an optimal debugging experience, while opting for Auto in production due to its superior user experience in most scenarios.
public static IComponentRenderMode Current => BuildConfigurationModeDetector.Current.IsDebug() ? BlazorServer : Auto;
Blazor Maui - Hybrid
Blazor can also be used to build native client apps using a hybrid approach. Hybrid apps are native apps that leverage web technologies for their functionality. In a Blazor Hybrid app, Razor components run directly in the native app (not on WebAssembly).
Blazor Hybrid is on top of .NET MAUI and has access to all native features of supported platforms (Android, iOS, macOS and Windows)
To switch to Blazor Hybrid mode:
  1. Set the "Server" project as the startup project.
  2. Select Boilerplate.Server-Swagger launchSettings profile instead of Boilerplate.Server-BlazorWebAssembly.
  3. Set "Maui" project as startup project and choose your Android, iOS, Windows, macOS emulator or device
  4. Debug target
  5. Change ApiServerAddress in Client/Boilerplate.Client.Core/appsettings.json to make sure your Android / iOS device can reach your computer.
  6. Right click on the solution file and open Properties
  7. Configure multiple-startup project by choosing Server and Maui projects and click on Ok
  8. Multi-startup solution
  9. Run the project