DevInstance.BlazorToolkit.Components
10.7.0
dotnet add package DevInstance.BlazorToolkit.Components --version 10.7.0
NuGet\Install-Package DevInstance.BlazorToolkit.Components -Version 10.7.0
<PackageReference Include="DevInstance.BlazorToolkit.Components" Version="10.7.0" />
<PackageVersion Include="DevInstance.BlazorToolkit.Components" Version="10.7.0" />
<PackageReference Include="DevInstance.BlazorToolkit.Components" />
paket add DevInstance.BlazorToolkit.Components --version 10.7.0
#r "nuget: DevInstance.BlazorToolkit.Components, 10.7.0"
#:package DevInstance.BlazorToolkit.Components@10.7.0
#addin nuget:?package=DevInstance.BlazorToolkit.Components&version=10.7.0
#tool nuget:?package=DevInstance.BlazorToolkit.Components&version=10.7.0
Blazor Toolkit
Blazor Toolkit is a comprehensive set of tools designed to enhance the development of Blazor applications. It provides a suite of utilities and services that streamline common tasks, allowing developers to focus on building rich, interactive web applications.
Features
Network Communication Tools: Simplify network operations such as making REST API calls. BlazorToolkit offers easy-to-use methods for handling HTTP requests and responses, reducing boilerplate code and potential errors.
Middleware Services: Implement middleware logic as services to abstract complex processes from the UI layer. This promotes a clean separation of concerns, making your application more modular and maintainable.
Form Validators: Integrate robust form validation mechanisms to ensure data integrity. The toolkit includes flexible validators that can be easily applied to your forms, providing immediate feedback to users and enhancing the overall user experience.
UI Components (separate package):
DevInstance.BlazorToolkit.Componentsships ready-made Bootstrap-styled components that plug into the service execution state:ErrorMessageBanner,PageProgress,LoadingProgress,DataPager,ModelDataPager,SortableHeader, and theBlazorToolkitPageLayoutlayout. Since 10.7.0 it also hasHDataGrid(sorting, paging, selection, grouping, resizable columns, column settings drawer, server-side search highlights) andHSearchBar. See docs/components.md.Offline-First Tools: Build offline-capable Blazor WebAssembly apps with an IndexedDB object store, connectivity tracking, a read-through cache, and a write-through outbox (sync queue). Reads serve local data immediately and refresh in the background; writes are persisted locally and replayed against the server when connectivity returns. See docs/offline-tools.md.
Installation
Blazor Toolkit package is available on NuGet (https://www.nuget.org/packages/DevInstance.BlazorToolkit/) and can be installed using the following command:
Power shell:
dotnet add package DevInstance.BlazorToolkit
Package manager:
Install-Package DevInstance.BlazorToolkit
The UI components (ErrorMessageBanner, DataPager, ModelDataPager, BlazorToolkitPageLayout, ...) are in a separate package that depends on the core one. Both packages are released with the same version number:
dotnet add package DevInstance.BlazorToolkit.Components
To use HDataGrid / HSearchBar, the host page also needs Bootstrap 5.3 CSS and its JS bundle, Bootstrap Icons, and the package stylesheet (no <script> tag for the grid: it loads its own JS module):
<link rel="stylesheet" href="_content/DevInstance.BlazorToolkit.Components/css/blazortoolkit-components.css" />
@* _Imports.razor *@
@using DevInstance.BlazorToolkit.Components.DataGrid
@using DevInstance.BlazorToolkit.Components.Search
Upgrading from 10.5.x or earlier: as of 10.6.0 the UI components moved out of
DevInstance.BlazorToolkitintoDevInstance.BlazorToolkit.Components(same namespace,DevInstance.BlazorToolkit.Components). Add the new package if you use any of them.ServiceExecutionHostComponentstays in the core package. See docs/USAGE.md.
Examples
Create a new Blazor WebAssembly project. Add new service class EmployeeService.cs and register it in Program.cs. Add new razor component Home.razor and inject EmployeeService into it. Use IServiceExecutionHost interface to handle service execution state.
EmployeeService.cs:
// Services are registered with Scoped lifetime by default
[BlazorService]
public class EmplyeeService
{
IApiContext<EmployeeItem> Api { get; set; }
public EmplyeeService(IApiContext<EmployeeItem> api)
{
Api = api;
}
public async Task<ServiceActionResult<EmployeeItemList?>> GetItemsAsync(int? top, int? page)
{
return await ServiceUtils.HandleWebApiCallAsync(
async (l) =>
{
var api = Api.Get();
if (top.HasValue)
{
api = api.Top(top.Value);
}
if (page.HasValue)
{
api = api.Page(page.Value);
}
return await api.ExecuteAsync<EmployeeItemList>();
}
);
}
}
Service Lifetimes: BlazorToolkit supports all DI service lifetimes:
// Scoped - instance per request/scope (default)
[BlazorService]
public class MyService { }
// Singleton - single instance for the entire application
[BlazorService(ServiceLifetime.Singleton)]
public class CacheService { }
// Transient - new instance for each injection
[BlazorService(ServiceLifetime.Transient)]
public class TemporaryService { }
Register service in DI container in Program.cs:
Program.cs:
static async Task Main(string[] args)
{
...
builder.Services.AddBlazorServices();
...
}
Add new razor component Home.razor and inject EmployeeService into it. Use IServiceExecutionHost interface to handle service execution state. BlazorToolkitPageLayout (from the DevInstance.BlazorToolkit.Components package) implements all necessary states like loading and error handling.
Home.razor:
@page "/"
@using DevInstance.BlazorToolkit.Components
@using DevInstance.BlazorToolkit.Services
@using DevInstance.EmployeeList.Client.Services
@using DevInstance.EmployeeList.Model
@using DevInstance.WebServiceToolkit.Common.Model
@layout BlazorToolkitPageLayout
<PageTitle>Home</PageTitle>
Welcome to your new app.
<ul>
@if (employees != null)
{
@foreach (var employee in employees.Items)
{
<li>@employee.Name</li>
}
}
</ul>
@code {
[Inject]
EmployeeService Service { get; set; }
[CascadingParameter]
public IServiceExecutionHost? Host { get; set; }
private EmployeeItemList employees = null;
protected override async Task OnInitializedAsync()
{
await Host.ServiceReadAsync(() => Service.GetItemsAsync(null, null, null), (e) => employees = e);
}
}
See more comprehensive example in DevInstance.BlazorToolkit.Samples project.
License
BlazorToolkit is licensed under the MIT License. You are free to use, modify, and distribute this software in accordance with the terms of the license.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- DevInstance.BlazorToolkit (>= 10.7.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
10.7.0
- New: HDataGrid (DevInstance.BlazorToolkit.Components.DataGrid) binding to IModelList<TItem>, with HColumnTemplate, HSortableHeader, GridSettings and ColumnDescriptor. Sort, page, group by column, resize columns, select rows, render server search highlights (IModelListHighlights).
- New: HSearchBar and SearchHighlight (DevInstance.BlazorToolkit.Components.Search).
- Needs Bootstrap 5.3 CSS and JS bundle plus bootstrap-icons, and the stylesheet _content/DevInstance.BlazorToolkit.Components/css/blazortoolkit-components.css. The grid's script is an ES module it imports itself: no script tag.
- Several grids and GridSettings on one page: give each pair its own HDataGrid.SettingsId / GridSettings.Id.
- Requires DevInstance.WebServiceToolkit.Common 10.4.0 (via DevInstance.BlazorToolkit 10.7.0).
10.6.0
- First release. The UI components (ErrorMessageBanner, PageProgress, LoadingProgress, DataPager, ModelDataPager, SortableHeader, BlazorToolkitPageLayout) moved here from DevInstance.BlazorToolkit 10.5.x. The namespace (DevInstance.BlazorToolkit.Components) is unchanged; ServiceExecutionHostComponent stays in the core package.
- Depends on DevInstance.BlazorToolkit with the same version; both packages are released together.
- Fixed: SortableHeader's label link pointed to the literal URL "SortLink" when UrlTemplate was set.
See https://github.com/devInstance/BlazorToolkit/blob/master/docs/USAGE.md#ui-components and docs/components.md