Mediatr query handler

From IntentArchitect/Intent.Modules.NET · View interactive version

Mediatr query handler is an AI agent skill from the GitHub repository IntentArchitect/Intent.Modules.NET. Implements business logic in MediatR query handler Handle methods. MUST load before creating or editing any query handler e.g. *QueryHandler.cs.

How to use this skill

Skill file

MediatR Query Handler

Implement query handler business logic inside an existing handler file. Keep handlers aligned with the modeled domain and existing query patterns while protecting architectural boundaries.

Core rules

Workflow

  1. Inspect the existing handler, request, response, repository or read-service abstractions, and related domain/read-model types.
  2. Search for code usages of:
  1. Infer the intended read behavior from the request shape, response contract, naming, and nearby feature implementations.
  2. Implement the Handle method using existing query patterns first.
  3. If the handler needs missing DAL capabilities, extend the relevant repository or read abstraction in an allowed layer instead of introducing infrastructure access into the handler.
  4. Add focused private helper methods when they make filtering, mapping, or result composition easier to understand.
  5. Ensure cancellation tokens are threaded through async calls where applicable.
  6. Verify the final code preserves layer boundaries and avoids infrastructure leakage.

Query-specific guidance

Queries usually read and shape data. Prefer patterns like these when supported by the surrounding codebase:

Repository and read abstraction guidance

When a needed read capability is missing:

EF Related Data Loading guidance

AutoMapper guidance

Example:


public class CustomerDtoProfile : Profile
{
    public CustomerDtoProfile()
    {
        CreateMap<Customer, CustomerDto>();
    }
}

public static class CustomerDtoMappingExtensions
{
    public static CustomerDto MapToCustomerDto(this Customer projectFrom, IMapper mapper) =>
        mapper.Map<CustomerDto>(projectFrom);

    public static List<CustomerDto> MapToCustomerDtoList(this IEnumerable<Customer> projectFrom, IMapper mapper) =>
        projectFrom.Select(x => x.MapToCustomerDto(mapper)).ToList();
}

Output expectations

Produce a concrete code update that:

Review checklist

Before finishing, check that:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.