TailoredApps.Shared.MediatR.PagedRequest 2.1.0

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

TailoredApps.Shared.MediatR.PagedRequest

PagedAndSortedRequest<TResponse, TQuery, TModel>: a base class for MediatR 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.MediatR.PagedRequest

Registration

Nothing to register: the package has no dependency-injection extension. Requests derived from the base class are ordinary MediatR 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.MediatR.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

  • 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.

Documentation

https://shared.tailoredapps.pl/en/Libraries/MediatR/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.2 51 11/12/2026
3.0.0-preview.1 56 11/12/2026
2.1.0 93 11/12/2026
2.0.1 89 11/12/2026
2.0.0 101 11/12/2026
1.6.0 89 11/12/2026
1.4.19 423 10/26/2026
1.4.18 522 10/23/2026
1.4.17 731 10/6/2026
1.4.16 118 9/28/2026
1.4.15 123 9/21/2026
1.4.14 122 8/20/2026
1.4.13 127 8/20/2026
1.4.12 146 8/20/2026
1.4.11 140 8/7/2026
1.4.10 249 7/8/2026
1.4.9 152 7/8/2026
1.4.8 148 7/6/2026
1.4.7 151 5/20/2026
1.4.6 150 5/20/2026
Loading failed