Aj Blazor Solution Template .NET 9 (Radzen)
Aj Blazor Solution Template .NET 9 (Radzen) is a modern, modular, and extensible Blazor WebAssembly application built on .NET 9. It provides a robust foundation for user, role, and permission management, leveraging best practices in authentication, authorization, and UI development with Radzen blazor.
Table of Contents
Features
- Blazor WebAssembly SPA with .NET 9
- Modular user, role, and permission management
- JWT-based authentication and role/permission-based authorization
- Modern UI with Radzen Blazor
- FastEndpoints for minimal, high-performance APIs
- Entity Framework Core with support for SQL Server, SQLite, and PostgreSQL
- Clean separation of client, server, and shared code
Project Structure
AjStarter.WebApp/
├── AjStarter.WebApp/ # Server-side (API, DB, Identity)
│ ├── Data/ # EF Core DbContext and configurations
│ ├── Endpoints/Identity/ # API endpoints for user, role, permission, token
│ ├── Services/Identity/ # Business logic for identity management
│ ├── Validators/ # FluentValidation for input validation
│ ├── Migrations/ # EF Core database migrations
│ └── ...
├── AjStarter.WebApp.Client/ # Blazor WebAssembly client
│ ├── Pages/Identity/ # UI pages for user, role, permission management
│ ├── Services/Identity/ # HttpClient-based API services
│ ├── Shared/Dtos/Identity/ # Data transfer objects (DTOs)
│ ├── Components/ # Reusable UI components
│ ├── Layout/ # Main layout and navigation
│ └── ...
User, Role & Permission Module
Key Features
- User Management: Create, update, delete users; assign roles.
- Role Management: Create, update, delete roles; assign permissions.
- Permission Management: Assign permissions to roles.
- Authentication: Login/logout with JWT tokens.
- Authorization: UI and API protected by roles and permissions.
Main Files
- API Endpoints:
Endpoints/Identity/UserEndpoint.cs
Endpoints/Identity/RoleEndpoint.cs
Endpoints/Identity/RolePermissionsEndpoint.cs
Endpoints/Identity/TokenEndpoint.cs
- Services:
Services/Identity/UserService.cs
Services/Identity/RoleService.cs
Services/Identity/RolePermissionService.cs
- Client Pages:
Pages/Identity/User/Users.razor
Pages/Identity/Role/Roles.razor
Pages/Identity/Role/RolePermissions.razor
- DTOs:
Shared/Dtos/Identity/RoleDto.cs
Shared/Dtos/Identity/Token.cs
Data Flow & Lifecycle
Example: Assigning Permissions to a Role
UI Loads:
RolePermissions.razor calls RoleService to fetch all permissions and assigned permissions for the selected role.
User Interaction:
User toggles checkboxes to assign/unassign permissions. Local state is updated.
Save:
On save, RoleService.AssignPermissionsAsync sends the updated list to the API.
API Endpoint:
RolePermissionsEndpoint receives the request, updates the database via RolePermissionService , and returns a result.
UI Updates:
The UI reflects the new assignments.
Blazor Lifecycle Methods Used
OnInitializedAsync : Fetches data when the page loads.
- Event handlers (e.g.,
OnPermissionToggled ): Update state on user actions.
- Async service calls: Communicate with the backend.
How to Run
Requirements
- .NET 9 SDK
- Visual Studio 2022 (latest recommended)
Setup
- Open the solution in Visual Studio.
- Restore NuGet packages.
- Apply EF Core migrations if needed (see
Migrations/ ).
Run
- Set
project as the startup project.
- Press F5 or Ctrl+F5 to run.
Access
- The app will open in your browser. Use the navigation menu to access user, role, and permission management.
Development Notes
- Blazor WebAssembly is used for the client UI. All business logic and API calls are handled via injected services.
- FastEndpoints provides minimal, high-performance API endpoints.
- Entity Framework Core is used for data access and migrations.
- RadzenBlazor is used for all UI components.
- Authentication/Authorization is enforced both in the UI (using
<AuthorizeView> ) and in the API endpoints.
- DTOs are used for all data transfer between client and server.
References
This project is a solid starting point for building secure, modular, and modern Blazor WebAssembly applications with robust user, role, and permission management.
| |