I am rebuilding some view models to make easier to maintain and I want to use inheritance, now I know how to get the view model to inheriate the necessary properties, however my question is how to populate them.
Lets say I have a Employee, Customer, and Guest viewModel, that all inheriate 5 things, if I have a controller for each model that allows me to update them, that would mean I have to create the model and populate it with the inheriated properties on each
controller, so I effectively have to create the same code in each controller to populate the same inheriated fields.
So whats the best way to go about populating the properties so I can maintain them better?
Did you actually look at the
documentation? I think they've thoroughly documented every single feature in AutoMapper. There is also a robust
AutoMapperSamples solution that gives a ton of code examples.
EnenDaveyBoy
Participant
1465 Points
1146 Posts
viewModel Inheritance Question
Apr 03, 2012 11:53 AM|LINK
Hi
I am rebuilding some view models to make easier to maintain and I want to use inheritance, now I know how to get the view model to inheriate the necessary properties, however my question is how to populate them.
Lets say I have a Employee, Customer, and Guest viewModel, that all inheriate 5 things, if I have a controller for each model that allows me to update them, that would mean I have to create the model and populate it with the inheriated properties on each controller, so I effectively have to create the same code in each controller to populate the same inheriated fields.
So whats the best way to go about populating the properties so I can maintain them better?
BrockAllen
All-Star
27530 Points
4905 Posts
MVP
Re: viewModel Inheritance Question
Apr 03, 2012 03:04 PM|LINK
Automapper is a popular library for doing this.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
EnenDaveyBoy
Participant
1465 Points
1146 Posts
Re: viewModel Inheritance Question
Apr 03, 2012 07:03 PM|LINK
Thanks, but the documention isn't very good IMO, there simply isn't enough of it.
ryanw51
Contributor
2363 Points
511 Posts
Re: viewModel Inheritance Question
Apr 03, 2012 07:18 PM|LINK
Did you actually look at the documentation? I think they've thoroughly documented every single feature in AutoMapper. There is also a robust AutoMapperSamples solution that gives a ton of code examples.