Skip to content

LaunchPad owns validation: Rocket.Surgery.LaunchPad.Validation replaces ZeroAlloc.Validation #3374

Backlog
0 of 6 issues completed

Description

@david-driscoll

What

LaunchPad owns validation. A new package, Rocket.Surgery.LaunchPad.Validation, with its own analyzer package (Rocket.Surgery.LaunchPad.Validation.Analyzers), writes one validator per validated type at build time and replaces ZeroAlloc.Validation everywhere in this repository.

The spec is docs/design/validation.md (added with the first sub-issue); the decision is recorded in ADR-0012.

Why

ZeroAlloc.Validation is attribute-only, its generator can't compose with [Mutable] and [InheritFrom], and LaunchPad controls neither its output nor its vocabulary.

Shape

The rules of a type come from several places, merged into one generated validator:

  • LaunchPad rule attributes, and the known System.ComponentModel.DataAnnotations attributes compiled inline.
  • Function validators: static void Validate(IValidationBuilder<T> v, ...dependencies).
  • Class validators: constructor-injected, implementing IValidator<T>.
  • The rules of T's base classes and interfaces.
  • The rules carried over by [InheritFrom<T>] and [Mutable<T>], across assemblies, through a rule manifest.

Validators are found by shape; the Validate bodies are a build-time DSL the generator rewrites. Nothing is interpreted at run time: no reflection, no expression trees. A validator is synchronous unless a rule is async; synchronous use of an async validator is a build error with a code fix.

Done when

  • No project, sample or test references ZeroAlloc.Validation or ZeroAlloc.Mediator.Validation.
  • The mediator pipeline, the build-time OpenAPI schema rules, Blazor forms, options validation and the [Mutable] validators run on the new package, and the samples are ported.
  • A native AOT sample validates a request with no warnings from validation.

Out of scope

FluentValidation API compatibility or a migration shim; a runtime rule engine; arbitrary C# statements in Validate bodies; a separate repository.

Part of #3045.

Sub-issues

Sub-issues

0 of 6 Issues completed
Loading 6 sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions