Creating Custom Blazor Component Pages in Bloqs
You can create custom pages or components for your Bloqs applications inside the UserInterface Components project. These pages are full Blazor components, meaning you can define routes, inject services, query data, and execute commands just like in any Blazor application.
1. Page Routing
Define a route at the top of your .razor page using the @page directive. Use the following format:
@page "/<your-app-name>/<your-page-name>"For example, a charts page for sample-app would be:
@page "/sample-app/charts"2. Injecting Services
You can inject standard Bloqs services as well as your own custom services:
IQueryDispatcher – for querying data
ICommandDispatcher – for executing commands such as create, save, delete, or operations
IRunContext – for retrieving tenant and runtime context information
Example injection in your page:
@inject IQueryDispatcher queryDispatcher
@inject ICommandDispatcher commandDispatcher
@inject IRunContext runContext
@inject MyCustomService myService3. Querying Data
Use IQueryDispatcher to query entities from your app. Here’s an example for querying Activity entities for the current tenant:
4. Executing Commands
Use ICommandDispatcher to create, save, delete, or perform other operations on entities:
5. Example: Charts Page
Here is a full example page showing charts using MudBlazor:
Key Points
Routes: Always use
/app-name/page-nameformat.Data Access: Use
IQueryDispatcherandICommandDispatcher.Tenant Awareness: Use
IRunContextto retrieve the current tenant.Custom Services: You can inject and use any service your page requires.
Blazor Features: You can use standard Blazor features like
@code, data binding, lifecycle methods, and component libraries (e.g., MudBlazor).
Last updated