Skip to content
OpenSmartRoute
Skillv1.0.0

coreex-validator

Create or modify a CoreEx validator in the Application layer. USE FOR: new Validator<T,TSelf> (no injection), new Validator<T> with constructor injection, AbstractValidator<T,TSelf> (FluentValidation-

by Avanade(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from Avanade/CoreEx (.github/skills/coreex-validator/SKILL.md). Install upstream with npx skills add Avanade/CoreEx --skill coreex-validator. Copyright stays with the author.

CoreEx: Validator

Guides you through creating or modifying a CoreEx validator (Application/Validators/) for a contract or request type. Covers declarative rules, ref-data validation, async database checks, collection and dictionary validators.

When to Use

  • New validator for a contract or request type (no database calls needed)
  • New validator that requires a repository or other Application-layer dependency
  • Adding property rules or an async check to an existing validator
  • Nested validator for a sub-property (.Entity()), a collection, or a dictionary
  • Switching to FluentValidation-compatible AbstractValidator syntax

When Not to Use

  • Domain invariants (aggregates, entities, value objects) — those belong in the Domain layer
  • Infrastructure-level data checks that are not accessed via an Application-layer interface
  • FluentValidation NuGet package — AbstractValidator here is CoreEx.Validation.AbstractValidator

Quick Reference

Clarifying questions to ask before writing any code:

  1. Does the validator need a constructor-injected dependency (e.g. a repository)? (determines base class)
  2. Which properties need validation? (list upfront — batch type resolution, don't interrupt per-property)
  3. Are any ref-data properties required? Optional? (.Mandatory().IsValid() vs .IsValid())
  4. Are any checks async (e.g. confirming an entity exists in the database)?
  5. Does the user prefer FluentValidation-style RuleFor(x => ...) syntax?

Base class decision:

Situation Base class Notes
No injection needed Validator<T, TSelf> Exposes Default singleton; invoke via .Default.ValidateAndThrowAsync(...)
Constructor injection needed Validator<T> No Default; instantiate at the call site with already-injected dependencies: new {Name}Validator(_dep).ValidateAndThrowAsync(...)
FluentValidation-style preferred AbstractValidator<T, TSelf> RuleFor(x => ...) / NotEmpty() / IsValid() — still CoreEx; has Default

Key rules at a glance:

  • Ref-data: .IsValid() on the navigation property (Gender), never on *Code string
  • Mandatory() on a non-nullable value type errors on default (0, MinValue) — use a range rule if 0 is valid
  • Runtime-computed thresholds: use delegate overloads (.LessThanOrEqualTo(_ => ...)) — prefer over OnValidateAsync imperative logic
  • context.HasErrors guard before async I/O; context.HasError(x => x.Prop) for per-property guards
  • context.AddError(x => x.Prop, ...) — member-access expression, never nameof(...)
  • Message text argument is a {2} suffix substitution — not a full sentence; use .Error("...") to override the whole message
  • Always generate or update the matching {Validator}Tests in *.Test.Unit/Validators/ — cover conditional/business rules and cross-field logic thoroughly, plus a representative error/success pair for simple rules; skip dedicated boundary tests for framework-guaranteed constraints like length rules (MaximumLength/MinimumLength/Length/String)

For full workflow, rule reference, and code examples see references/workflow.md.

Key References

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/avanade-coreex-coreex-validator/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

avanade-coreex-coreex-validator.ocm.jsonjson
{
  "ocm": "1",
  "id": "avanade-coreex-coreex-validator",
  "kind": "skill",
  "name": "coreex-validator",
  "description": "Create or modify a CoreEx validator in the Application layer. USE FOR: new Validator<T,TSelf> (no injection), new Validator<T> with constructor injection, AbstractValidator<T,TSelf> (FluentValidation-style), adding rules to an existing validator, nested entity/collection/dictionary validators. DO NOT USE FOR: domain invariants in aggregates, FluentValidation NuGet package, Infrastructure-layer checks.",
  "publisher": "Avanade",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "general"
    ],
    "tags": [
      "skill-md",
      "validators",
      "validation",
      "application-layer",
      "coreex",
      "fluent-rules",
      "async",
      "github"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Create or modify a CoreEx validator in the Application layer. USE FOR: new Validator<T,TSelf> (no injection), new Validator<T> with constructor injection, AbstractValidator<T,TSelf> (FluentValidation-style), adding rules to an existing validator, nested entity/collection/dictionary validators. DO NOT USE FOR: domain invariants in aggregates, FluentValidation NuGet package, Infrastructure-layer checks."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "github",
      "repository": "https://github.com/Avanade/CoreEx",
      "path": ".github/skills/coreex-validator/SKILL.md",
      "ref": "6bffd0651340b8feaf7fd1ab49980ef509ef2876",
      "url": "https://github.com/Avanade/CoreEx/blob/6bffd0651340b8feaf7fd1ab49980ef509ef2876/.github/skills/coreex-validator/SKILL.md",
      "key": "Avanade/CoreEx/.github/skills/coreex-validator/SKILL.md"
    }
  },
  "instructions": "<!--\n  AI workflow asset — dual-audience notice:\n  - In the Avanade/CoreEx repository: this file is the authored source. Edit it here.\n  - In a consumer repository: this file was generated by `dotnet new coreex-ai` (or refreshed via\n    `dotnet new coreex-ai --force` / the `/coreex-docs-sync` skill). Do not hand-edit it directly —\n    propose the change upstream in Avanade/CoreEx instead, then refresh once it is released.\n-->\n\n# CoreEx: Validator\n\nGuides you through creating or modifying a CoreEx validator (`Application/Validators/`) for a contract or request type. Covers declarative rules, re",
  "cost": {
    "context_tokens": 1223
  }
}

Fetch it by URL: GET /api/v1/registry/avanade-coreex-coreex-validator/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.