TailoredApps.Shared.Mediator.PagedRequest 3.0.0-preview.3

This is a prerelease version of TailoredApps.Shared.Mediator.PagedRequest.
dotnet add package TailoredApps.Shared.Mediator.PagedRequest --version 3.0.0-preview.3
                    
NuGet\Install-Package TailoredApps.Shared.Mediator.PagedRequest -Version 3.0.0-preview.3
                    
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="TailoredApps.Shared.Mediator.PagedRequest" Version="3.0.0-preview.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TailoredApps.Shared.Mediator.PagedRequest" Version="3.0.0-preview.3" />
                    
Directory.Packages.props
<PackageReference Include="TailoredApps.Shared.Mediator.PagedRequest" />
                    
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 TailoredApps.Shared.Mediator.PagedRequest --version 3.0.0-preview.3
                    
#r "nuget: TailoredApps.Shared.Mediator.PagedRequest, 3.0.0-preview.3"
                    
#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 TailoredApps.Shared.Mediator.PagedRequest@3.0.0-preview.3
                    
#: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=TailoredApps.Shared.Mediator.PagedRequest&version=3.0.0-preview.3&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=TailoredApps.Shared.Mediator.PagedRequest&version=3.0.0-preview.3&prerelease
                    
Install as a Cake Tool

TailoredApps.Shared.Mediator.PagedRequest

PagedAndSortedRequest<TResponse, TQuery, TModel>: a base class for mediator requests that return one page of a list. It carries the page, the page size, the sort field and direction and a filter object, so every list request in an application has the same shape. The contracts it implements come from TailoredApps.Shared.Querying.

Installation

dotnet add package TailoredApps.Shared.Mediator.PagedRequest

Registration

Nothing to register: the package has no dependency-injection extension. Requests derived from the base class are ordinary mediator requests (IRequest<TResponse>).

Usage

The handler below uses the paging and sorting extensions of TailoredApps.Shared.EntityFramework, which accept the request directly and validate what the client sent.

using TailoredApps.Shared.EntityFramework.Querying;
using TailoredApps.Shared.Mediator.PagedRequest;
using TailoredApps.Shared.Querying;

public class ProductFilter : QueryBase
{
    public string? NameContains { get; set; }
}

public class GetProducts : PagedAndSortedRequest<PagedResult<ProductDto>, ProductFilter, ProductDto>
{
}

public class GetProductsHandler(ShopDbContext db) : IRequestHandler<GetProducts, PagedResult<ProductDto>>
{
    public async Task<PagedResult<ProductDto>> Handle(GetProducts request, CancellationToken cancellationToken)
    {
        IQueryable<Product> products = db.Products;

        var name = request.Filter?.NameContains;
        if (!string.IsNullOrWhiteSpace(name))
        {
            products = products.Where(p => p.Name.Contains(name));
        }

        var page = await products
            .ApplySorting(request, ["Name", "Price"])   // allow-list of sort fields
            .PagingAsync(request);

        return page.Project(p => new ProductDto(p.Id, p.Name, p.Price));
    }
}
Member Meaning
Page, Count Page number (1-based) and page size; null means no paging
IsPagingSpecified true when both Page and Count have a value
SortField, SortDir Field to sort by and SortDirection (Asc, Desc)
IsSortingSpecified true when SortField is not blank and SortDir has a value
Filter The filter object, a class derived from QueryBase
IsSortBy(fieldName) Compares SortField with a field name, ignoring case

Good to know

  • Built on ForkForward.Mediator, a fork of MediatR 12.5.0 under the Apache-2.0 licence, not on the MediatR package: requests and handlers use the ForkForward.Mediator namespace and the mediator is registered with AddMediator(...). In 2.x this package was named TailoredApps.Shared.MediatR.PagedRequest.
  • TQuery must derive from QueryBase and TResponse must implement IPagedResult<TModel>.
  • The class only carries the values. Page, Count and SortField usually come straight from the HTTP request and are not checked here: a handler that calls Skip/Take itself has to limit the page size.
  • PagingAsync and ApplySorting in TailoredApps.Shared.EntityFramework do check them: the page must be at least 1, the page size between 1 and PagingQuery<T>.MaxPageSize (1000 by default), and the sort field a single property name, optionally from an allow-list. Violations throw ArgumentOutOfRangeException or ArgumentException.
  • IsSortingSpecified is also true for SortDirection.Undefined.
  • The types of this package are safe for trimming and NativeAOT; the EntityFramework extensions used in the handler above are not (EF Core).

Documentation

https://shared.tailoredapps.pl/en/Libraries/Mediator/PagedRequest/

Product 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.  net11.0 is compatible. 
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
3.0.0-preview.3 47 12/2/2026