pipeline-behaviors

Implement MediatR pipeline behaviors for validation, logging, performance, and transactions.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Centralizes cross-cutting concerns in MediatR pipelines to avoid boilerplate scattered across handlers.

Core Features & Use Cases

  • ValidationBehavior for pre-request validation using FluentValidation-like patterns.
  • LoggingBehavior for structured logging around requests with timing metrics.
  • PerformanceBehavior to warn on slow requests and provide diagnostics.
  • TransactionBehavior to optionally wrap requests in database transactions via a marker interface.
  • UnhandledExceptionBehavior to log and rethrow unexpected errors.
  • Simple DI wiring to apply all behaviors in a consistent order across the app.

Quick Start

Configure MediatR in your startup to register the pipeline behaviors and immediately start benefiting from standardized cross-cutting concerns.

Frequently Asked Questions about pipeline-behaviors

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

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

Centralize cross-cutting concerns in MediatR by implementing pipeline behaviors that intercept requests globally, applying validation, logging, and transactional support consistently without scattering boilerplate across individual handlers.

How do I add performance monitoring to MediatR pipeline behaviors?

Add performance monitoring to MediatR pipeline behaviors by implementing a PerformanceBehavior class that warns on slow requests and provides diagnostics, then wiring it into the pipeline during startup registration.

Can I wrap MediatR requests in a database transaction using pipeline behaviors?

Wrap MediatR requests in database transactions by implementing a TransactionBehavior class that optionally intercepts requests via a marker interface, executing the handler within a transactional scope during pipeline execution.

What is the best way to handle validation in a .NET CQRS pipeline?

Handle validation in a .NET CQRS pipeline using a ValidationBehavior class that applies FluentValidation-like pre-request checks, ensuring invalid requests fail early before reaching the handler logic.

How do I configure MediatR pipeline behaviors during .NET startup registration?

Configure MediatR pipeline behaviors during .NET startup by registering the behavior classes in a consistent order using simple DI wiring, immediately applying standardized cross-cutting concerns across all application requests.

Why do I need pipeline behaviors for unhandled exceptions in MediatR?

Pipeline behaviors for unhandled exceptions intercept unexpected errors globally using an UnhandledExceptionBehavior class that logs the failure and rethrows the error, preventing scattered try-catch blocks across handlers.