RevalQuery.Blazor 0.1.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package RevalQuery.Blazor --version 0.1.2
                    
NuGet\Install-Package RevalQuery.Blazor -Version 0.1.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RevalQuery.Blazor" Version="0.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RevalQuery.Blazor" Version="0.1.2" />
                    
Directory.Packages.props
<PackageReference Include="RevalQuery.Blazor" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RevalQuery.Blazor --version 0.1.2
                    
#r "nuget: RevalQuery.Blazor, 0.1.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RevalQuery.Blazor@0.1.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RevalQuery.Blazor&version=0.1.2
                    
Install as a Cake Addin
#tool nuget:?package=RevalQuery.Blazor&version=0.1.2
                    
Install as a Cake Tool

RevalQuery

A high-performance, Result-oriented data fetching library for Blazor.

Heavily inspired by TanStack Query, BlazorQ brings a professional-grade state management and caching layer to .NET 8+. It is designed for developers who value type safety, explicit error handling via the Result Pattern, and architecture that works across both Blazor WebAssembly and Blazor Server.


📦 Installation

Register the core services in your Program.cs.

//Program.cs

builder.Services.AddScoped<QueryClient>();
builder.Services.AddSingleton<QueryPluginsPipeline>();

🏗 Component Integration

Before using the following functions, your components must inherit from the base class:

@inherits BlazorQ.QueryComponentBase

🔍 Using Queries (UseQuery)

The UseQuery method allows you to observe a piece of data.

Stateless Handlers

Handlers must be stateless. Using the static keyword on your lambda is the best way to enforce this; it prevents the closure from capturing component-level variables and ensures the compiler helps you stay safe.

private IQueryState<BasketItem?> quantityQuery => UseQuery(
    
    QueryOptionsFactory.Create
    (
        key: ("basket-count", itemId),
        
        handler: static async ctx =>
        {
            // Access services via the context ServiceProvider
            var basketService = ctx.ServiceProvider.GetRequiredService<IBasketService>();
            var item = await basketService.GetItem(ctx.Key.itemId);
            return QueryResult.Success(item);
        },
        
        onSuccess: async (basketItem) =>
        {
            Console.WriteLine($"Fetched quantity: {basketItem?.Quantity}");
        },
        
        enabled: OperatingSystem.IsBrowser() // Only fetch on the client side
    ), 
    cancellationTokenSource
);

💡 Pro Tip: For better reusability and cleaner components, define your QueryOptions in a static factory class ( e.g., BasketQueries.GetItemOptions(itemId)).

To enforce architectural purity, use the stateless validation plugin during development. This ensures your handlers don't accidentally capture external state, which can lead to memory leaks or stale closures.

//Program.cs

if (builder.Environment.IsDevelopment())
{
    // Throws errors at runtime if handlers capture state
    builder.Services.AddSingleton<IQueryPlugin, QueryPluginHandlersStatelessValidation>();
}

⚡ Mutations

Unlike Queries, Mutations are used for server-side actions (Create/Update/Delete). These can be stateful and are the recommended place to perform cache invalidation using the QueryClient.

private IMutationState<string, Task> addItemMutation => UseMutation(
    MutationOptionsFactory.Create<string, Task>
    (
        handler: async (ctx) =>
        {
            var basketService = ctx.ServiceProvider.GetRequiredService<IBasketService>();
            var queryClient = ctx.ServiceProvider.GetRequiredService<QueryClient>();
    
                await basketService.AddItem(new(ctx.Params, 1));
                
                // Invalidate specific cache keys to trigger re-fetches
                queryClient.Invalidate(("basket-count", ctx.Params));
                
                return Task.CompletedTask;
        }
    ) 
);

🛠 Features

Callbacks & Lifecycle

Queries support lifecycle callbacks (onSuccess, onError, onSettled). These allow you to trigger side effects—like Toast notifications or logging—without polluting your UI logic.

Multi-Targeting

BlazorQ is built to target .NET 8, .NET 9 and .NET 10 (2026 Ready).


⚠️ Dev Release Note

This is a development release. The API is subject to change.


License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.0 89 5/7/2026
0.2.0 100 4/8/2026
0.1.3 99 3/25/2026
0.1.2 98 3/24/2026
0.1.1 97 3/24/2026