Web Api Model validation | .Net 5 | Asp.net Core

Опубликовано: 05 Август 2026
на канале: AzureTeach•Net
3,281
54

This video demonstrates Web API Model validation in .net 5 and asp.net core. It has clear explanation for Asp.net Core Web API Model Validation using Fluent Validation, Validation Attribute, IValidatableObject and Data Annotations.
--------------------------------------------------------------------------
This video gives you clear understanding on When to use Validation Attribute, When to use IValidatableObject Interface, When to use Data Annotations and When to use Fluent Validation.
--------------------------------------------------------------------------
When to use IValidatableObject interface in Asp.net Core Web API?
When you want to apply the validation logic only on a Specific model only then you can use IValidatableObject Interface in Asp.net Core/.Net 5 Web API.
------------------------------------------------------------------------
When to use ValidationAttribute in Asp.net Core Web API?
When you want to make your ValidationAttribute logic reusable and want to use it on other models, then you can use ValidationAttribute in Asp.net Core/ .Net 5 Web API.
------------------------------------------------------------------------
When to use Fluent Validation in Asp.net Core Web API?
When you want to make your asp.net core Web API validation logic unit testable, then you can use Fluent Validation in Asp.net Core Web API/.net 5. Remaining all other kind of validations are in built in asp.net core/.Net5 but for Fluent Validation you have to Add FluentValidation.AspNetCore Nuget Package. Then we have to create a validator class by inheriting from AbstractValidator class of Fluent Validation for asp.net core Web API. Then we have to register the validator class in services part of Startup.cs class. In addition, we have to call AddFluentValidation() method too.
----------------------------------------------------------------------
When to use Data Annotations in Asp.net Core Web API?
Data Annotations in Asp.net Core Web API are pretty much used any where when we need to do Model Validation in Asp.net Core Web API as these are basic kind of validations. Below are predefined data annotations in Asp.net Core Web API / .Net 5
Required
RegularExpression
Range
StringLength
EmailAddress

----------------------------------------------------------------

00:00 Introduction
00:50 ValidationAttribute in .Net5/Asp.net Core Web API
09:57 IValidatableObject in .Net 5/Asp.net Core Web API
12:30 Data Annotations in .Net 5/Asp.net Core Web API
17:47 Fluent Validation in .Net 5/Asp.net Core Web API