cqrs-basics

Implement CQRS with MediatR commands and queries in .NET projects.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides clear guidance and patterns to avoid mixed responsibilities and tightly coupled logic by separating commands (writes) from queries (reads) when building .NET applications.

Core Features & Use Cases

  • Command and Query Patterns: Naming conventions and example request/response DTOs for Create/Update/Delete commands and Get/List queries.
  • Handlers and Pipeline Behaviors: Sample MediatR handlers, registration guidance, and pipeline behavior ordering for validation, logging, and transactions.
  • Integration Advice: Minimal API and Controller wiring examples, database query best-practices such as AsNoTracking, and folder organization for Clean Architecture and VSA projects.
  • Use Case: Build an order management feature with CreateOrderCommand handlers, validators, and ListOrdersQuery handlers that return paged responses.

Quick Start

Add CQRS by creating command and query types, register MediatR and pipeline behaviors, and move controller logic into handlers to enforce separation of concerns.

Frequently Asked Questions about cqrs-basics

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

FAQPage Schema
How do I separate command and query responsibilities in a .NET Clean Architecture project?

Implement CQRS with MediatR in your .NET Clean Architecture project to separate state-changing commands from read-only queries using distinct request types and handlers. This enforces separation of concerns and prevents tightly coupled logic.

How do I configure MediatR pipeline behaviors for validation and logging in .NET?

Configure MediatR pipeline behaviors by registering validation and logging behaviors in your .NET dependency injection container. Order the pipeline behaviors so validation executes before logging and transaction behaviors to fail fast on invalid command requests.

What naming conventions should I use for CQRS commands and queries with MediatR?

Use explicit naming conventions for CQRS commands and queries such as CreateOrderCommand and ListOrdersQuery. Match these with dedicated handler classes and specific request/response DTOs to maintain clarity across your Clean Architecture or VSA project structure.

Does this CQRS pattern with MediatR work with Vertical Slice Architecture?

Yes, the CQRS pattern with MediatR works with Vertical Slice Architecture. It provides guidance for folder organization and handler registration that applies to both Clean Architecture and VSA .NET projects organizing commands, queries, and pipeline behaviors.

How do I optimize read-only queries in a CQRS .NET application?

Optimize read-only queries in a CQRS .NET application by applying AsNoTracking to your database read operations. This prevents the Entity Framework change tracker from overhead processing on ListOrdersQuery handlers returning paged responses.

Do I need FluentValidation to implement CQRS pipeline behaviors?

FluentValidation is optional for implementing CQRS pipeline behaviors. The pattern supports optional FluentValidation integration alongside unit-of-work persistence patterns to validate command requests before they reach the handler execution phase.