pipeline-behaviors

Compose MediatR pipeline behaviors for logging, validation, and exception handling.

69|13|Updated Jan 26, 2026
One-click install
npx skills add https://github.com/ronnythedev/dotnet-clean-architecture-skills --skill pipeline-behaviors
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pipeline-behaviors
Source: https://github.com/ronnythedev/dotnet-clean-architecture-skills/tree/main/sample/POS/.claude/skills/10-pipeline-behaviors
Command: npx skills add https://github.com/ronnythedev/dotnet-clean-architecture-skills --skill pipeline-behaviors

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires MediatR, FluentValidation.

What problem does it solve?

This skill provides a clean, reusable set of MediatR pipeline behaviors to handle logging, validation, exceptions, transactions, caching, and performance monitoring across commands and queries.

Core Features & Use Cases

  • Centralizes cross-cutting concerns (LoggingBehavior, ValidationBehavior, ExceptionHandlingBehavior, TransactionBehavior, QueryCachingBehavior, PerformanceBehavior, IdempotencyBehavior).
  • Enables consistent results, robust error handling, and transactional integrity across application layers.
  • Use Case: Apply a uniform validation and logging strategy to all handlers in a clean architecture project to improve observability and reliability.

Quick Start

Install MediatR dependencies and register the behaviors in your DI container, in order from outermost to innermost (Logging, Performance, Validation, ExceptionHandling, Transaction). Example: in your application startup, register OpenGeneric behaviors for each Behavior<,> and ensure FluentValidation validators are registered.

Frequently Asked Questions about pipeline-behaviors

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

FAQPage Schema
How do I handle cross-cutting concerns like logging and validation in MediatR?

Cross-cutting concerns in MediatR are handled using pipeline behaviors that wrap command and query handlers. This skill provides reusable behaviors for logging, validation, exception handling, and transactions to centralize these operations across your application execution pipeline.

How do I register MediatR pipeline behaviors in the correct order?

Register MediatR pipeline behaviors in your DI container from outermost to innermost: Logging, Performance, Validation, ExceptionHandling, and Transaction. This sequence ensures logging captures the full execution context before validation short-circuits invalid requests.

Can I use FluentValidation with MediatR for automated request validation?

Yes, FluentValidation integrates with MediatR through a ValidationBehavior pipeline component. It automatically intercepts requests, validates them against registered FluentValidation validators, and short-circuits the execution pipeline if validation fails.

Does this MediatR pipeline skill support both commands and queries?

Yes, the pipeline behaviors apply to both commands and queries in .NET projects. It supports open generic registrations for unified processing while including specific behaviors like QueryCachingBehavior tailored for non-mutating query operations.

How do I standardize exception handling across MediatR handlers?

Exception handling is standardized using an ExceptionHandlingBehavior that wraps handler execution. It catches exceptions thrown during processing and translates them into standardized Result or Result<T> objects for consistent error responses across the application.

What is the best way to implement transaction management in a clean architecture MediatR project?

Transaction management is implemented using a TransactionBehavior in the MediatR pipeline. It wraps command handlers to ensure transactional integrity across application layers, committing successful operations and rolling back failures automatically.

Related Skills