Folks,
I'm trying to figure out a pattern or best practice to translate data from the domain objects/data source over to the 'ViewModel' object. In my particular example, the domain object is the WCF proxy objects. Any call to the WCF methods will populate these proxy objects which finally gets transferred over to the 'ViewModel' objects. See Architectural diagram
This microsoft article: http://msdn.microsoft.com/en-us/magazine/dd419663.aspx talks about using a Repository pattern. It's mentioned under 'The Data Model and Repository' section. Is that the best approach? Can someone advice me?
dorman
Repository pattern is related to data access layer (what is inside your WCF). This has nothing to do with presentation layer.
I would suggest you declare your Model and ViewModel classes in MVC project based on the requirements for the UI (without taking your database schema into consideration). You can then use AutoMapper to simplify the code needed to copy values from WCF proxy classes to your Models. You might want to encapsulate this code in an Adapter class that will shield the rest of app from AutoMapper code.
EDIT:
Do not use your WCF proxies as model classes. Declare separate model classes based on your UI and use AutoMapper to copy data between them.
Yes, you need to have a repository. That will give you some advantages, like easy testing of the view model; also an easy switching to another kind of repository later.
In terms of the article you provided, - it gave them an advantage of unit-testing the view-model logic; and, later on, they can switch from XML files repository to the SQL server repository (as an example).
Just make sure to have abstract repository injected into ViewModel.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With