coreex-validator

Creates and modifies CoreEx validators with declarative rules, async checks, and unit tests.

28|8|Updated Feb 21, 2022
One-click install
npx skills add https://github.com/Avanade/CoreEx --skill coreex-validator-avanade
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: coreex-validator
Source: https://github.com/Avanade/CoreEx/tree/main/.github/skills/coreex-validator
Command: npx skills add https://github.com/Avanade/CoreEx --skill coreex-validator-avanade

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing consistent, correct validation logic in CoreEx-based .NET applications requires knowing which base class to use, how to chain rules, and how to handle async database checks — this Skill guides that entire workflow so validators follow CoreEx conventions every time. ## Core Features & Use Cases - Base class selection: Chooses between Validator<T, TSelf> (no injection), Validator<T> (constructor injection), and AbstractValidator<T, TSelf> (FluentValidation-style syntax) based on your needs. - Rule authoring: Covers mandatory fields, ref-data validation with .IsValid(), comparison rules, precision/scale, conditional rules (WhenEntity, WhenValue, DependsOn), and nested entity, collection, and dictionary validators. - Async validation: Implements OnValidateAsync overrides with context.HasErrors guards for database lookups and cross-field checks. - Use Case: You need a validator for a Product contract that checks SKU length, validates a ref-data category, and asynchronously confirms products exist in the database — the Skill scaffolds the validator, wires the async check, and generates the matching unit test class. ## Quick Start Ask the AI to create a CoreEx validator for your contract type, listing the properties to validate and any async database checks needed.

Frequently Asked Questions about coreex-validator

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

FAQPage Schema
How do I create a CoreEx validator for a contract type?▼

Inherit from Validator<T, TSelf> when no dependency injection is needed, which exposes a Default singleton. Add rules in the constructor using Property(x => x.Field) chains like .Mandatory().MaximumLength(50), then invoke via ValidateAndThrowAsync.

How do I add async database validation in CoreEx?▼

Use Validator<T> with constructor injection of your repository interface, then override OnValidateAsync. Guard with context.HasErrors before any I/O so expensive checks are skipped when cheap rules already failed.

Should I use the FluentValidation NuGet package with CoreEx?▼

No. CoreEx provides its own AbstractValidator<T, TSelf> in CoreEx.Validation with RuleFor syntax. Installing the FluentValidation package causes namespace collisions and is explicitly prohibited.

How do I validate reference data properties in CoreEx?▼

Call .IsValid() on the ref-data navigation property (e.g. Gender), never on the *Code string property. Use .Mandatory().IsValid() for required ref-data and .IsValid() alone for optional values.

Why does Mandatory() fail on valid zero values in CoreEx?▼

Mandatory() errors when a non-nullable value type equals its default, so 0 for decimal or int fails. Use .GreaterThanOrEqualTo(0) instead when zero is a legitimate value.

When should I not use a CoreEx validator?▼

Do not use it for domain invariants in aggregates or entities, which belong in the Domain layer, or for Infrastructure-level checks not accessed through an Application-layer interface.