Presentations : BlazorServer

The Presentation BlazorServer layer templates generate a complete Blazor Server application for each bounded context. The generator produces the project file, application entry point, dependency injection configuration, layout and menu components, home and error pages, resource files for localization, and a full CRUD UI for each entity — including list, details, create, edit, and delete dialogs — all driven by the entity and bounded context definitions configured in the Scaffolder.net UI.

Project File

The {{Solution.Name}}.Presentation.BlazorServer.{{BoundedContext.Name}}.csproj file defines the Blazor Server web project using the Microsoft.NET.Sdk.Web SDK. It includes project references to the Infrastructure.Persistence project (which transitively brings in the Application and Domain projects) and the Shared.Presentation, Shared.Presentation.Blazor, and Shared.Presentation.BlazorServer projects, providing access to shared UI controls, Blazor abstractions, and BlazorServer-specific extensions.

Imports

It also injects shared services (IDialogService, IJSRuntime, NavigationManager) and string localizers for both the Domain and PresentationBlazorServer resources. The generator appends entity-specific @inject directives for each entity's query and command services via {PresentationBlazorServerGenerator.GetImports}.

Appsettings

The generator produces two application configuration files :
  • appsettings.json : Configures the default and supported localization cultures, Serilog sinks (Console and File with structured and readable log formats), and the logging minimum levels for the production environment.
  • appsettings.Development.json : Overrides Serilog minimum levels to Information for the Development environment, providing more verbose logging during development.

Global Usings

The GlobalUsings.cs file declares global using directives for the presentation project. It includes standard .NET namespaces, Microsoft ASP.NET Core and dependency injection namespaces, MudBlazor, Serilog, and shared presentation extension namespaces. The generator dynamically appends global usings for each entity's Application layer namespaces (commands, queries, errors, services) and Presentation BlazorServer namespaces (components, dependency injection, resources) via {PresentationBlazorServerGenerator.GetGlobalUsings}, ordered alphabetically by entity name.

Program

The Program.cs file contains the application entry point. It creates the WebApplicationBuilder, calls ConfigureWebApplicationBuilder to register all services, builds the WebApplication, logs startup information using Serilog, calls ConfigureWebApplication to set up the middleware pipeline, and runs the application. A global try-catch-finally block ensures fatal exceptions are logged and the logger is properly flushed on shutdown.

Components

The Components directory contains all Razor components for the Blazor Server application, organized into subdirectories for errors, entity features, home, layouts, menus, and the root routes file.

Components : Errors : NotFound

files generate a @page "/NotFound" route

Components : Errors : Unknown

files generate a @page "/UnknownError" route

Components : Features : Entity Commands : Create

For each entity, the generator produces a Create{{Entity.NameSingular}}Dialog with a Razor file and a code-behind file :
  • Create{{Entity.NameSingular}}Dialog.razor : Renders a DialogControl with a localized title, a loading state, form input controls generated by {PresentationBlazorServerGenerator.GetControls.WithId} (which produces TextFieldControl, NumericFieldControl, DatePickerControl, CheckBoxControl, or SelectEnumControl based on each property's type), and Cancel / Create action buttons.
  • Create{{Entity.NameSingular}}Dialog.razor.cs : A sealed partial class implementing IAsyncDisposable that holds a Create{{Entity.NameSingular}}CommandRequest, initializes non-nullable enum properties to their default values via {PresentationBlazorServerGenerator.GetEnumsDefaultValue}, calls the command service to create the entity, and closes the dialog with the result. Errors are displayed via ErrorManagerControl.

Components : Features : Entity Commands : Delete

For each entity, the generator produces a Delete{{Entity.NameSingular}}Dialog with a Razor file and a code-behind file :
  • Delete{{Entity.NameSingular}}Dialog.razor : Renders a DialogControl with a localized title, a loading state, a read-only SimpleTableControl displaying the entity's property values generated by {PresentationBlazorServerGenerator.GetTableRows.WithId}, and Cancel / Delete action buttons.
  • Delete{{Entity.NameSingular}}Dialog.razor.cs : A sealed partial class implementing IAsyncDisposable that receives the entity Id as a parameter, loads the delete confirmation data via the query service's GetDelete{{Entity.NameSingular}}Async method (navigating to /NotFound if the entity does not exist), shows a ConfirmDeleteDialogControl before deletion, calls the command service to delete the entity, and closes the dialog with the result.

Components : Features : Entity Commands : Edit

For each entity, the generator produces an Edit{{Entity.NameSingular}}Dialog with a Razor file and a code-behind file :
  • Edit{{Entity.NameSingular}}Dialog.razor : Renders a DialogControl with a localized title, a loading state, form input controls generated by {PresentationBlazorServerGenerator.GetControls} (without the Id field, since the Id is not editable), and Cancel / Save action buttons.
  • Edit{{Entity.NameSingular}}Dialog.razor.cs : A sealed partial class implementing IAsyncDisposable that receives the entity Id as a parameter, loads the edit data via the query service's GetEdit{{Entity.NameSingular}}Async method (navigating to /NotFound if the entity does not exist), populates the Edit{{Entity.NameSingular}}CommandRequest, calls the command service to edit the entity, and closes the dialog with the result.

Components : Features : Entity Queries : GetDetails

For each entity, the generator produces a details page and component :
  • Get{{Entity.NameSingular}}DetailsPage.razor : Defines a @page "/{{Entity.NamePlural}}/{{{Entity.NameSingular}}Id:{{Entity.IdType.ToLower}}}" route
  • Get{{Entity.NameSingular}}DetailsPage.razor.cs : A sealed partial class declaring the {{Entity.IdType}} {{Entity.NameSingular}}Id parameter with [EditorRequired].
  • Get{{Entity.NameSingular}}DetailsComponent.razor : Displays a localized heading, a loading state, a read-only SimpleTableControl with the entity's property values generated by {PresentationBlazorServerGenerator.GetTableRows.WithId}, and an Edit button that opens the Edit{{Entity.NameSingular}}Dialog.
  • Get{{Entity.NameSingular}}DetailsComponent.razor.cs : A sealed partial class implementing IAsyncDisposable that loads the entity details via the query service, handles the NotFound error by redirecting to /NotFound, and opens the edit dialog with the entity Id.

Components : Features : Entity Queries : GetList

For each entity, the generator produces a list page and component :
    Get{{Entity.NameSingular}}ListPage.razor : Defines a @page "/{{Entity.NamePlural}}" route
  • Get{{Entity.NameSingular}}ListPage.razor.cs : A sealed partial class declaring the namespace.
  • Get{{Entity.NameSingular}}ListComponent.razor : Displays a localized heading, a loading state, a DataGridControl with property columns generated by {PresentationBlazorServerGenerator.GetDataGridPropertyColumns.WithId}, a details hyperlink icon column, and a delete icon button column. An Add button opens the Create{{Entity.NameSingular}}Dialog.
  • Get{{Entity.NameSingular}}ListComponent.razor.cs : A sealed partial class implementing IAsyncDisposable that loads the entity list via the query service, orders the results by Id, and provides methods to open the create and delete dialogs. After a successful dialog action, the list is reloaded.

Components : Home

The page defines a @page "/" route

Components : Layouts

The MainLayoutComponent.razor and its code-behind generate the main application layout. The layout uses MudBlazor's MudLayout with a cascading dark-mode value, a MudAppBar containing a menu toggle button (with localized show/hide titles), the project name, a LanguageSelectorControl, and a dark/light mode toggle button. A MudDrawer hosts the MainMenuComponent, and MudMainContent renders the page body. The code-behind class manages the menu open state and dark mode preference via localStorage through JS interop, and configures a custom MudTheme with dark palette colors.

Components : Menus

The MainMenuComponent.razor and its code-behind generate the application navigation menu. The menu renders a NavMenuControl with a Home link and one NavLinkControl per entity, generated by {PresentationBlazorServerGenerator.GetMenu}, which produces links to the /{{Entity.NamePlural}} route with localized display names. Each link uses NavLinkMatch.Prefix matching.

Components : Routes

The Routes.razor file defines the Blazor Router component, wrapped in an ErrorManagerControl. The router uses the presentation assembly (referenced via the {{Solution.Name}}PresentationBlazorServer{{BoundedContext.Name}}AssemblyReference marker type), sets the MainLayoutComponent as the default layout, and routes to the NotFoundErrorPage when no route matches.

Dependency Injection

The DependencyInjection directory contains two extension classes that configure the Blazor Server application :
  • WebApplicationBuilderExtension : A static class with a ConfigureWebApplicationBuilder method that registers Serilog, localization, Application services, Infrastructure.Persistence services, MudBlazor services, and Blazor Server services.
  • WebApplicationExtension : A static class with a ConfigureWebApplication method that configures the Blazor Server middleware pipeline, Serilog request logging, request localization, cookie culture, FluentValidation display name resolution (using the Application and Domain resource types), and Blazor Server endpoints.

Properties

The launchSettings.json file defines the HTTPS launch profile for the development environment, with the application URL set to https://localhost:7100, ASPNETCORE_ENVIRONMENT set to Development, and the browser launch option enabled.

Resources

The Resources directory contains the localization resource class and its associated .resx file :
  • {{Solution.Name}}PresentationBlazorServer{{BoundedContext.Name}}Resource.cs : A sealed marker class used by the IStringLocalizer infrastructure to resolve localized strings for the presentation layer.
  • {{Solution.Name}}PresentationBlazorServer{{BoundedContext.Name}}Resource.resx : The resource file containing localized strings for the layout (project name, menu toggle titles, dark/light mode titles), main menu (Home link, entity plural names generated by {PresentationBlazorServerGenerator.GetResources}), home page, error pages, and entity-specific page titles, headings, and dialog labels for list, details, create, edit, and delete operations — all humanized from the entity names.

wwwroot

The wwwroot directory contains the static web assets for the Blazor Server application :
  • Default.css : Defines custom CSS styles for headings, the language selector control (with dark and light mode variants), and dialog control title and content styling.
  • Default.js : An empty JavaScript file placeholder for custom client-side scripts.
  • favicon.png : The binary favicon image served as the browser tab icon. This file is copied as binary content without tag replacement.

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please reload the page.