ASP.NET Core Minimal API request model validation in .NET 10
- One minute read - 137 wordsThis post is an update to my previous post on ASP.NET Core Minimal API request model validation.
With the release of .NET 10, request model validation using DataAnnotations attributes is now built-in to ASP.NET Core
for minimal APIs.
You can read the release notes to see what’s needed, but it’s pretty simple and just what you would expect. No need for external packages!
If you applied model validation to your minimal APIs following my previous post using MinimalApis.Extensions then all you need to do is:
- remove calls to the
WithParameterValidation()in yourMapGroup()andMapXXX()calls - remove the package reference to
MinimalApis.Extensions - add
builder.Services.AddValidation()in yourProgram.cs
That’s it!
If you need the features of FluentValidation instead of
DataAnnotations then you will still need to follow the steps outlined in my previous post.
Once again, happy validating!