mediatr-command-handler

Implements business logic in MediatR command handler Handle methods following clean architecture layer boundaries.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing MediatR command handlers often leads to layer violations, infrastructure leakage, and inconsistent patterns across a codebase. This Skill guides the implementation of Handle methods so business logic stays in the right layer, follows existing domain patterns, and respects strict rules around repositories, Unit of Work, and AutoMapper. ## Core Features & Use Cases - Guided Handle Method Implementation: Fills in or corrects the Handle method of existing *CommandHandler.cs files while preserving method signatures and IntentManaged attributes. - Layer Boundary Enforcement: Prevents direct dependencies on Entity Framework, Dapper, DbContexts, or other infrastructure types inside handlers, directing data access through Domain/Application repository abstractions. - Strict Data Access Rules: Enforces no in-memory aggregation, no unnecessary SaveChangesAsync calls, no redundant repository Update calls with EF tracking, and mandatory AutoMapper usage for DTO projections. - Use Case: When adding a new command like CreateOrderCommandHandler, the Skill inspects existing handlers, repositories, and domain entities, then implements the Handle method using established patterns such as loading aggregates, invoking domain behavior, and returning the standard result type. ## Quick Start Implement the Handle method in my CreateCustomerCommandHandler.cs following the existing repository and domain patterns in this solution.

Frequently Asked Questions about mediatr-command-handler

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

FAQPage Schema
How do I implement a MediatR command handler in C#?▼

Implement the Handle method by loading the aggregate through a repository abstraction, invoking domain behavior on entities, and returning the established result type. Keep orchestration in the handler and place durable business rules in domain entities or services.

How to avoid Entity Framework dependencies in MediatR handlers?▼

Inject only Domain or Application layer abstractions such as repository interfaces, never DbContexts, EF Core packages, or SQL clients. If a data capability is missing, extend the repository abstraction contract first rather than pulling infrastructure into the handler.

When should I call SaveChangesAsync in a command handler?▼

Call SaveChangesAsync only when the operation returns a payload requiring DB-generated values like an Id, RowVersion, or computed column. For commands returning Unit or void, omit it and assume an outer unit-of-work pipeline commits the changes.

Should I use AutoMapper or manual DTO mapping in query handlers?▼

AutoMapper is mandatory for read paths returning DTOs derived from domain entities. Verify the CreateMap exists in a Profile before using ProjectTo methods, and create the profile under Mappings/<Feature>/<Entity>DtoProfile.cs if it is missing.

Why should I avoid repository Update calls with Entity Framework?▼

EF tracks entities loaded from the repository automatically, so calling Update is redundant. Modify entity properties directly and let the Unit of Work persist tracked changes, reserving Add and Delete for inserts and removals.

Can I use Include or ThenInclude in the Application layer?▼

No, Include and ThenInclude are only available in the Infrastructure layer. Lazy loading with proxies and Owns-based composition load navigation properties automatically, but heavy lazy loading should be moved into the repository layer.