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
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
- 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
Informationfor 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
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
@page "/NotFound" route
Components : Errors : Unknown
@page "/UnknownError" route
Components : Features : Entity Commands : Create
Create{{Entity.NameSingular}}Dialog with a Razor file and a code-behind file :
- Create{{Entity.NameSingular}}Dialog.razor : Renders a
DialogControlwith a localized title, a loading state, form input controls generated by{PresentationBlazorServerGenerator.GetControls.WithId}(which producesTextFieldControl,NumericFieldControl,DatePickerControl,CheckBoxControl, orSelectEnumControlbased on each property's type), and Cancel / Create action buttons. - Create{{Entity.NameSingular}}Dialog.razor.cs : A sealed partial class implementing
IAsyncDisposablethat holds aCreate{{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 viaErrorManagerControl.
Components : Features : Entity Commands : Delete
Delete{{Entity.NameSingular}}Dialog with a Razor file and a code-behind file :
- Delete{{Entity.NameSingular}}Dialog.razor : Renders a
DialogControlwith a localized title, a loading state, a read-onlySimpleTableControldisplaying 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
IAsyncDisposablethat receives the entity Id as a parameter, loads the delete confirmation data via the query service'sGetDelete{{Entity.NameSingular}}Asyncmethod (navigating to/NotFoundif the entity does not exist), shows aConfirmDeleteDialogControlbefore deletion, calls the command service to delete the entity, and closes the dialog with the result.
Components : Features : Entity Commands : Edit
Edit{{Entity.NameSingular}}Dialog with a Razor file and a code-behind file :
- Edit{{Entity.NameSingular}}Dialog.razor : Renders a
DialogControlwith 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
IAsyncDisposablethat receives the entity Id as a parameter, loads the edit data via the query service'sGetEdit{{Entity.NameSingular}}Asyncmethod (navigating to/NotFoundif the entity does not exist), populates theEdit{{Entity.NameSingular}}CommandRequest, calls the command service to edit the entity, and closes the dialog with the result.
Components : Features : Entity Queries : GetDetails
- 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}}Idparameter with[EditorRequired]. - Get{{Entity.NameSingular}}DetailsComponent.razor : Displays a localized heading, a loading state, a read-only
SimpleTableControlwith the entity's property values generated by{PresentationBlazorServerGenerator.GetTableRows.WithId}, and an Edit button that opens theEdit{{Entity.NameSingular}}Dialog. - Get{{Entity.NameSingular}}DetailsComponent.razor.cs : A sealed partial class implementing
IAsyncDisposablethat loads the entity details via the query service, handles theNotFounderror by redirecting to/NotFound, and opens the edit dialog with the entity Id.
Components : Features : Entity Queries : GetList
- Get{{Entity.NameSingular}}ListPage.razor : Defines a
- 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
DataGridControlwith property columns generated by{PresentationBlazorServerGenerator.GetDataGridPropertyColumns.WithId}, a details hyperlink icon column, and a delete icon button column. An Add button opens theCreate{{Entity.NameSingular}}Dialog. - Get{{Entity.NameSingular}}ListComponent.razor.cs : A sealed partial class implementing
IAsyncDisposablethat 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.
@page "/{{Entity.NamePlural}}" route
Components : Home
@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
DependencyInjection directory contains two extension classes that configure the Blazor Server application :
- WebApplicationBuilderExtension : A static class with a
ConfigureWebApplicationBuildermethod that registers Serilog, localization, Application services, Infrastructure.Persistence services, MudBlazor services, and Blazor Server services. - WebApplicationExtension : A static class with a
ConfigureWebApplicationmethod 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
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
IStringLocalizerinfrastructure 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
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.