query-handler

Implement MediatR query handlers with paginated, filtered DTO results from repositories.

4|1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill query-handler
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: query-handler
Source: https://github.com/FaysilAlshareef/dotnet-ai-kit/tree/main/skills/microservice/query/query-handler
Command: npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill query-handler

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill standardizes the implementation of MediatR query handlers so that list and single-entity queries are paginated, filtered, and mapped to DTO outputs consistently across a .NET microservice codebase, reducing duplicated query logic and incorrect data returns.

Core Features & Use Cases

  • Uses an IUnitOfWork with named repositories so handlers delegate filtering, pagination, and sorting to repository methods.
  • Defines list query records with pagination and filter parameters, and output classes with PageSize, CurrentPage, Total, and typed collections for predictable paging responses.
  • Covers single-entity queries that use FindAsync then map to DTOs and throw domain-specific not-found exceptions; supports injecting additional services for enrichment when needed.

Quick Start

Create a GetOrdersHandler that uses IUnitOfWork.Orders to return a paginated GetOrdersOutput mapped to OrderOutput.

Frequently Asked Questions about query-handler

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement paginated MediatR query handlers in a .NET microservice?

Implement MediatR query handlers by delegating filtering, pagination, and sorting to repository methods via IUnitOfWork, then map results to output DTOs. This approach standardizes list and single-entity queries across your .NET microservice codebase to ensure predictable paging responses.

What does a paginated DTO output need for MediatR query responses?

A paginated DTO output needs PageSize, CurrentPage, Total, and typed collections. Defining list query records with these properties ensures predictable paging responses and consistent data returns across domain repositories in your .NET application.

How do I handle single-entity queries with MediatR and IUnitOfWork?

Handle single-entity queries by using FindAsync on named repositories through IUnitOfWork, then map the result to a DTO. If the entity is missing, throw domain-specific not-found exceptions to maintain consistent error handling across the query layer.

Can I inject additional services into a MediatR query handler for data enrichment?

Yes, you can inject additional services into a MediatR query handler for enrichment when needed. The handler delegates core filtering and pagination to repository methods but supports injecting extra services to append supplementary data to the DTO output.

Does this query handler approach require repository-level encapsulation for filtering and sorting?

Yes, this approach requires repository-level encapsulation of filtering, pagination, and sorting. Handlers delegate these operations to named repositories accessed via IUnitOfWork, preventing duplicated query logic and incorrect data returns across the microservice codebase.

What's the best way to standardize query logic across a C# microservice codebase?

Standardize query logic by using MediatR query handlers that delegate to IUnitOfWork named repositories for filtering and pagination. This reduces duplicated logic by enforcing repository-level encapsulation and returning DTOs with consistent PageSize, CurrentPage, and Total properties.