MediatR pipeline behavior chặn request trước khi handler thực thi.
- Đăng ký behavior:
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>)). - Dùng để logging, validation, caching, authorization mà không sửa từng handler.
- Thứ tự behavior quan trọng — thường là: validation → caching → logging → handler.
- Giữ handler tập trung vào business logic; giảm boilerplate.
- Chuẩn công nghiệp cho clean architecture với MediatR.
MediatR pipeline behaviors intercept requests before handlers execute.
- Register behaviors via
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>)). - They enable logging, validation, caching, and authorization without modifying individual handlers.
- Behavior order matters — typically: validation → caching → logging → handler.
- Handlers stay focused on business logic; cross-cutting concerns are decoupled.
- Industry standard for clean architecture with MediatR.