Using DataAnnotations in DDD Projects

5

We have a doubt that the analyst raised when using DataAnnotations in the ViewModel in projects that use DDD in the case has a Domain layer and in case it will not expand, this use would eliminate the domino layer because it is duplicating the field validation, for example:

I am validating if the email was filled in this case would need to do this validation again in the domain?

    
asked by anonymous 11.01.2018 / 12:46

1 answer

8

I am validating if the email was filled in this case would need to do this validation again in the domain?

R.: Yes, the validation you use in the viewmodel is to be used by the validation on the client (although validate on the server also with model.isvalid). You should not use the business entity as ViewModel. Always use a viewmodel to transfer only the data you need to display in the view. To automatically populate the viewmodel use Automapper and to make the entity validation rules use FluentValidation.

    
11.01.2018 / 12:58