0

Until now I have had a Model and ViewModel, neither with constructors and a Helper Class that has methods for mapping to and from the Model/ViewModel.

This is because that is the way that I have seen it in every tutorial.

What I was wondering is why not add a constructor to the ViewModel that has the Model as a Parameter and put the mapping code in there?

You would need a blank constructor for when you wanted a ViewModel without a model, that's no hardship.

The logical progression of this is to do the same with the Model for going the other way.

Is this breaking some golden rule? Is there some reason I've not seen it done?

Tom

Tom
  • 119
  • 1
  • 7
  • 16
  • You can take a look at here https://stackoverflow.com/questions/10511853/constructor-in-viewmodel – Furkan Öztürk Mar 06 '20 at 06:16
  • If you always did this, you end up tying your viewmodel class to several different models, in different assemblies. It might work for small projects, but IMO it's a bad habit to start. – Neil Mar 06 '20 at 06:41

0 Answers0