mediatr-query-handler

Implements business logic in MediatR query handler Handle methods in C#.

23|10|Updated Aug 31, 2017
One-click install
npx skills add https://github.com/IntentArchitect/Intent.Modules --skill mediatr-query-handler-intentarchitect
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: mediatr-query-handler
Source: https://github.com/IntentArchitect/Intent.Modules/tree/main/Tests/Accelerators/.agents/skills/mediatr-query-handler
Command: npx skills add https://github.com/IntentArchitect/Intent.Modules --skill mediatr-query-handler-intentarchitect

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing MediatR query handlers that respect layered architecture is error-prone: developers often leak infrastructure concerns (EF Core, Dapper, DbContexts) into the Application layer, compute aggregations in memory, or misuse Unit of Work and AutoMapper. This Skill guides the implementation of the Handle method so handlers stay aligned with domain models and existing query patterns. ## Core Features & Use Cases - Layer-boundary enforcement: Ensures handlers only depend on Domain or Application abstractions and never reference infrastructure packages like Entity Framework or Dapper. - Query pattern guidance: Applies existing repository, projection, pagination, filtering, and mapping conventions found in the codebase before inventing new approaches. - Strict data-access rules: Enforces AutoMapper for DTO projections, forbids in-memory aggregation, and controls SaveChangesAsync and repository Update usage. - Use Case: When adding a new GetCustomerOrdersQueryHandler.cs, use this Skill to implement the Handle method using the existing repository abstraction, AutoMapper projection, and cancellation-token-aware async calls. ## Quick Start Implement the Handle method in my OrdersQueryHandler.cs following the mediatr-query-handler skill rules and existing repository patterns.

Frequently Asked Questions about mediatr-query-handler

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

FAQPage Schema
How do I implement a MediatR query handler Handle method?▼

Update only the Handle method body in the existing handler file, keeping its signature unchanged and setting the IntentManaged attribute Body to Mode.Ignore. Retrieve data through existing Domain or Application repository abstractions and map results with AutoMapper.

Can I use Entity Framework Include or DbContext in a MediatR handler?▼

No. Handlers must never reference infrastructure types such as DbContext, EF Include/ThenInclude, Dapper, or SQL clients. Data access goes through Domain or Application repository abstractions, which you extend contract-first when a read capability is missing.

When should SaveChangesAsync be called in a query handler?▼

Only call SaveChangesAsync when the operation returns a payload requiring DB-generated values such as a surrogate key, RowVersion, or computed column. For queries returning Unit, void, or plain DTOs, omit it and rely on the ambient unit of work.

How do I handle aggregations like Count or Sum in a query handler?▼

Never compute aggregations in memory inside the handler. Extend the appropriate repository or read abstraction with a method returning the aggregated result, then call it from the handler.

Why must query handlers use AutoMapper instead of manual DTO construction?▼

Read paths returning Application-layer DTOs derived from Domain entities must use AutoMapper projections. Before using ProjectTo methods, verify a CreateMap exists in a Profile or create the profile under Mappings/<Feature>/<Entity>DtoProfile.cs.