This repository contains a comprehensive guide to .NET's System.ComponentModel.DataAnnotations validation system. It covers everything from built-in attributes through advanced extensibility, and explores the path toward adding async validation to DataAnnotations. The material is designed to bring a team up to speed so they can build a project plan for adding async validation across the entire .NET product suite.
- Built-In Validation Attributes — Complete catalog of attributes shipped with .NET
- Creating Custom Validation Attributes — Deriving from
ValidationAttributefor reusable rules - Annotating Objects for Validation — Applying attributes to properties and classes
- Programmatic (Manual) Validation — Using the
Validatorclass directly - ASP.NET MVC Automatic Validation — How model binding triggers validation
- Advanced Custom Validation —
IValidatableObjectand complex validation scenarios - ValidationContext Deep Dive — Services, Items dictionary, and context propagation
- The ValidationResult API — Understanding validation results and error reporting
- The Async Validation Gap — Why DataAnnotations lacks async support today
- Strickland — Parallel Concepts and Async Validation — Lessons from a JavaScript validation framework
- The History of DataAnnotations Integration Across .NET — Chronological history of every integration point
- The Async Validation Prototype — A Working Demo — Analysis of a working async validation prototype
- Object Graph Validation — Recursive walks, result representation, and ecosystem solutions
- Appendix A: .NET Integration Points Catalog — Every framework that consumes DataAnnotations
- Appendix B: Complete Reference Link Library — All source links and documentation references
For team members who are new to DataAnnotations validation, the recommended reading order below starts with the foundational blog series, moves through official API documentation, then application model integration, and finishes with async validation concepts.
DataAnnotations validation saw its most significant innovation during the .NET RIA Services era (2009–2012), when APIs like IValidatableObject, ValidationResult, ValidationContext, and Validator were designed and refined. The 2010 RIA Services Validation blog series was written against RIA Services but covers the universal DataAnnotations framework, and it remains one of the most thorough walkthroughs available.
- Standard Validators —
[Required],[Range],[StringLength],[RegularExpression]; error messages and localization - Custom Validation Methods — Using
[CustomValidation]to delegate to static methods - Custom Reusable Validators — Deriving from
ValidationAttribute; theIsValid(object, ValidationContext)override - Attribute Propagation — How validators flow between tiers
- Validation Triggers — When validation is invoked
- Cross-Field Validation — Validating one property based on another
- Entity-Level Validation — Class-level validation and the 4-stage pipeline
- Providing ValidationContext — Items dictionary, IServiceProvider, ServiceContainer
- Using ValidationContext (Cross-Entity Validation) — Service-based validators that access data stores
- ViewModel Validation with Entity Rules — Reusing validation across view models
Additional Resources:
- GitHub repository with sample code: jeffhandley/RIAServicesValidation
- Video tutorials (VB): RIA Services Validation Video Tutorials
- System.ComponentModel.DataAnnotations Namespace
- Validator Class API
- ValidationAttribute Class
- ValidationContext Class
- ValidationResult Class
- ASP.NET Core MVC Model Validation
- Blazor Forms Validation
- Options Pattern Validation —
ValidateDataAnnotations(),ValidateOnStart() - EF Core Data Annotations
- ASP.NET Core OpenAPI
- WPF Data Validation
- WinForms Input Validation
- Strickland Documentation / GitHub
- Strickland: Inspiration
- Strickland: Two-Stage Sync/Async Validation
- Chapter 11: The History of DataAnnotations Integration Across .NET — Chronological history of every integration point with PR/issue citations
- Chapter 12: The Async Validation Prototype — A Working Demo — Analysis of the
oroztocil/validation-demobranch - Microsoft.Extensions.Validation design issue (dotnet/aspnetcore#46349) — Unified validation design proposal
- Minimal API validation PR (dotnet/aspnetcore#60724) — Core implementation of Minimal API validation
- Core source analysis — dotnet/runtime, dotnet/aspnetcore, dotnet/efcore, and dotnet/aspire repositories, tracing validation integration history through PRs and commits
- Historical foundation — The RIA Services Validation blog series (2010) and research into how RIA Services and OpenRiaServices approached async validation patterns
- Official documentation — Microsoft Learn conceptual and API docs for ASP.NET Core MVC, Blazor, Options pattern, EF Core, OpenAPI, WPF, and WinForms validation
- Async validation prototype — Analysis of the
oroztocil/validation-demobranch and the Microsoft.Extensions.Validation design - Ecosystem research — Strickland (JavaScript validation framework), MiniValidation (Damian Edwards), FluentValidation, Blazor component vendors (MudBlazor, Radzen, Telerik, Syncfusion, DevExpress), API frameworks (FastEndpoints, ServiceStack), and schema generators (Swashbuckle, NSwag)
- The material targets team members who will work on adding async validation across the .NET product suite
This repository is licensed under the MIT License. See the LICENSE file for details.