mediatr

Implement MediatR commands, queries, handlers, and pipeline behaviors in .NET applications.

Updated Apr 9, 2026
One-click install
npx skills add https://github.com/nist0/CoDev --skill mediatr
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mediatr
Source: https://github.com/nist0/CoDev/tree/main/.github/skills/mediatr
Command: npx skills add https://github.com/nist0/CoDev --skill mediatr

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires MediatR, and includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill helps developers implement Command Query Responsibility Segregation (CQRS) patterns using MediatR, ensuring a clean separation of commands and queries, and a structured application layer with robust pipeline behaviors.

Core Features & Use Cases

  • CQRS Implementation: Guides on creating commands, queries, handlers, and pipeline behaviors for CQRS architecture.
  • Pipeline Behaviors: Instructions for adding cross-cutting concerns like logging, validation, and caching.
  • Handler Testing: Guidance on testing handlers in isolation and within the full pipeline.
  • Use Case: For a developer looking to refactor an application to use CQRS for better performance and maintainability.

Quick Start

Use the mediatr skill to implement a command for creating a new order in your application.

Frequently Asked Questions about mediatr

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

FAQPage Schema
How do I implement CQRS patterns in a .NET application using MediatR?

MediatR implements CQRS patterns by separating commands and queries into distinct handlers, ensuring a clean application layer structure. It guides the creation of handler components and integrates pipeline behaviors for cross-cutting concerns.

What is the best way to add logging or validation to a MediatR pipeline behavior?

Pipeline behaviors handle cross-cutting concerns like logging, validation, and caching within the MediatR pipeline. You implement these behaviors to intercept commands and queries, applying rules before or after the main handler executes.

Do I need the MediatR library to use CQRS command and query separation?

Yes, this Skill requires the MediatR library as a dependency to implement the CQRS pattern. It provides the foundational in-memory messaging infrastructure necessary for routing commands and queries to their respective handlers.

How do I unit test MediatR handlers in isolation?

You test MediatR handlers in isolation by mocking dependencies and verifying command or query execution independently. The Skill provides guidance on testing handlers both individually and within the full pipeline behavior context.

When should I refactor my application to use the CQRS pattern?

Refactor to the CQRS pattern when you need better performance and maintainability through strict command and query separation. It is ideal for applications requiring a structured application layer with robust cross-cutting pipeline behaviors.

Can I use MediatR pipeline behaviors for caching in C#?

Yes, MediatR pipeline behaviors support cross-cutting concerns including caching. You can implement caching logic within a custom pipeline behavior to intercept queries and return cached responses before reaching the handler.