Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *


  1. hey Mukesh,
    Is it possible to use validator objects with Fluent Validation in a class library either model class or a separate class library?

    1. Absolutely. When building applications with Clean Architecture in mind, it is quite important to separate the object in order to maintain loose coupling. You can separate these objects to another class library as well. Thanks

  2. Hello Mukesh,

    Very good tutorial. I would also like to know how to use fluent validations with Resource files in a multilingual site.

    Thank you.

  3. Hello Mukesh,

    This is a great article. I have a question though, if I wanted to limit the size of my fields and specify the data type in the database should I use DataAnnotations using code-first?
    Because when I try to run update-database strings are created as nvarchar(max)
    I want it to be created as varchar(n).

    Thank you and regards,

    1. Validation is applicable only when you want to validate user input. Do not confuse it with how an entity is defined. In an ideal architecture, you would validate the DTO Class / View Model class only. Entities should have no Data Annotations / Validations and should have the properties only. I would suggest creating a ViewModel over your Entity and then validate it. If valid, map it to the entity using AutoMapper maybe. Refer –


      1. Thank you Mukesh for your quick response. But still, I want to know where do I setup the column data types and length if I want to limit the size in the database. Should I change it in the migration code itself? What is ideal for this case? Because if all will be using nvarchar(max) it is not ideal in database administration perspective.

        Again thank you and regards

  4. Hello Mukesh,
    I am very happy with all of your articles…
    I am trying to develop a Net Core Winforms application with clean arch. in mind.
    Two questions, first of all is which is the best system to implement DI in Winforms?
    The second one is I supposse I have to implement a Validator with FluentValidation for every entity and inject this validator before use the repository, is correct?
    I have between 50-100 entities and I want to know if there is some trick to implement the validation or the solution is create all the validators, register it in the IoC container and inject as needed.
    Thanks a million.

  5. What should be done if it is required to validate in the database, for example, that the email is unique. How can I add the database context to the validator?

  6. Hi, i was trying to register the wrong package, i was installed the FluentValidation.DependencyInjectionExtensions hahahhaha, thanks to your first step i fix the problem.

  7. For manual error response, it is more appropriate to return a ValidationProblemDetails with 400 or 422 status