I refactor my code in order to respect the view model pattern. I also used the AutoMapper. Now, I have a question related to ‘Required’ and ‘DisplayName’ annotations. Originally I set these annotations on the model. I thought this was the best place to be. But now that I use a viewModel on my views I’m wondering
Do I have to move ‘DisplayName’ and ‘Required’ annotations from my model to my view model classes?
I noticed that my annotations on my models are no more detected in my views (now based on view models).
Thanks for your help.
Yes, in fact, annotations are one of the reasons to have view models, because then you don’t have to pollute your domain classes with annotations, that are only meaningful in particular view.
It’s tempting to have everything in one place, to be really DRY, but domain model may be not interested at all in whatever is going in your views. It’s not his responsibility. It’s common fight between don’t repeat yourself and single responsibility, you have to find the sweet spot between them:)