mediatorlite-validation

Configure MediatorLite v2 validation pipelines with correct dual-layer wiring.

4|1|Updated Jan 11, 2026
One-click install
npx skills add https://github.com/behl1anmol/MediatorLite --skill mediatorlite-validation
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mediatorlite-validation
Source: https://github.com/behl1anmol/MediatorLite/tree/main/.cursor/skills/mediatorlite-validation
Command: npx skills add https://github.com/behl1anmol/MediatorLite --skill mediatorlite-validation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

MediatorLite v2's source-generation-first validation model eliminates manual pipeline configuration, but agents and developers often introduce hard-to-debug issues by hand-registering behaviors, placing validators in unscanned assemblies, or misusing the error contract. This Skill eliminates those misconfigurations and ensures validation works as intended with zero redundant setup.

Core Features & Use Cases

  • Dual-Layer Validation Guidance: Covers both built-in DataAnnotations attribute validation and custom business-rule IValidator<T> implementations, with clear rules for when to use each.
  • Error Contract & Pipeline Semantics: Teaches how to work with ValidationResult, ValidationError, and ValidationException to surface consistent, structured validation errors at API boundaries like HTTP 400 responses.
  • Anti-Pattern Prevention: Flags common v2 mistakes including duplicate ValidationBehavior<,> registration, relying on [BehaviorOrder] to adjust validation priority, and throwing from ValidateAsync instead of returning failure results.
  • Use Case Example: If you are adding input validation to a new MediatorLite CreateOrderCommand and need to ensure both attribute checks (like [Required] on the CustomerId property) and custom business rules (like verifying the customer exists in the database) run correctly without breaking the source-generated pipeline, this Skill provides the exact steps and guardrails.

Quick Start

Use the mediatorlite-validation skill to add attribute-based and custom business rule validation to your new MediatorLite order creation request, and configure your API to return structured 400 error responses for any invalid input.

Frequently Asked Questions about mediatorlite-validation

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

FAQPage Schema
How do I add validation to MediatorLite v2 request pipelines without breaking source generation?

To add MediatorLite v2 validation without breaking source generation, avoid hand-registering pipeline behaviors and place validators in scanned assemblies so the source-generation-first architecture discovers them automatically. This prevents manual configuration errors while ensuring full validation coverage.

How does dual-layer validation work with Data Annotations and FluentValidation in MediatorLite?

Dual-layer validation in MediatorLite combines built-in Data Annotations attribute checks like [Required] with custom business-rule IValidator<T> implementations. This dual-layer validation model runs attribute checks first, then executes custom validators to enforce complex business rules within the request pipeline.

Why is my MediatorLite validation behavior executing twice or throwing exceptions?

Duplicate validation behavior execution in MediatorLite is a common v2 anti-pattern caused by manually hand-registering ValidationBehavior<,> instead of relying on source generation. Additionally, throwing exceptions from ValidateAsync instead of returning failure results disrupts the pipeline and causes runtime errors.

How do I return consistent HTTP 400 error responses for MediatorLite validation failures?

To return consistent HTTP 400 error responses for MediatorLite validation failures, implement the error contract using ValidationResult, ValidationError, and ValidationException. This surfaces structured validation errors at API boundaries, ensuring clients receive consistent failure details instead of unhandled exceptions.

Do I need .NET 10 to use source-generated MediatorLite validation pipelines?

Yes, source-generated MediatorLite validation pipelines require .NET 10 or later projects. MediatorLite v2 leverages the source-generation-first architecture available in .NET 10+ to automatically wire validation behaviors, eliminating the need for manual pipeline configuration and preventing duplicate behavior registration.

When should I use Data Annotations versus custom IValidator implementations in MediatorLite?

Use Data Annotations in MediatorLite for basic property-level input validation like [Required] fields, and implement custom IValidator<T> rules for complex business logic such as verifying database record existence. This separation ensures dual-layer validation wiring remains consistent and maintainable.