dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.22k stars 4.72k forks source link

Feature request: Proper validation in .NET! #40157

Open weitzhandler opened 4 years ago

weitzhandler commented 4 years ago

Background and Motivation

Validation is one of the most critical building blocks in any application, server or client. Yet the .NET lacks an official and adequate solution to this matter.

DataAnnotations validation have been integrated with the .NET for a long time. With the advancement of .NET it's been discovered that although decorating properties with inline attributes is a neat way to define validation, it comes with many limitations by the compiler (i.e. attributes may only take in constants, no generics etc.), as well as other downsides. DA has over time become completely abandoned and from what I read (will update when I find source), is no longer planned to be updated or be taken to the next level.

Additionally, UI frameworks (especially UWP and WinUI), don't have a conventional way of rendering the validation errors and exchanging validation data across app layers.

Proposed solution

My suggestion hereby is for Microsoft and the .NET to thoroughly rethink the subject of validation and introduce (or officially adopt an existing) a fully integrated validation framework open for configuration, customization and extensibility, engineered from scratch to cover or enable extensibility of as many scenarios as possible, for instance (some less or not important as others - no specific order):

Microsoft.Extensions sounds to me like the perfect family validation would fit in. It would benefit from integration with its siblings:

It could come in two blocks:

Future / 2nd blcok:

Dotnet-GitSync-Bot commented 4 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

eerhardt commented 4 years ago

@ericstj @maryamariyan - thoughts?

ericstj commented 4 years ago

It sounds like an idea for a brand new library / suite of libraries. Typically we don't start those out here in dotnet/runtime unless there is a super compelling reason they need to be in this layer (like intrinsics). @weitzhandler why not start out a project independent of of dotnet/runtime and see how it goes. If you can make a compelling case for integration it can be something to consider. Also cc @davidfowl (extensions architect) and @ajcvickers (annotations and EF owner) for opinions.

ajcvickers commented 4 years ago

@weitzhandler I've had discussions on this with several people in the last few months. It's something we're thinking about, but we don't have any concrete plans yet.

/cc @jeffhandley @DamianEdwards

weitzhandler commented 4 years ago

Typically we don't start those out here in dotnet/runtime unless there is a super compelling reason they need to be in this layer

Personally I think validation is one of the most important building blocks in any application. As of today, the .NET lacks a dedicated validation engine that covers today's validation requirements.

It's something we're thinking about, but we don't have any concrete plans yet.

Thanks for your input!