The document discusses the ViewModel pattern in MVC applications. It explains that domain models returned from data access layers are not suitable for views. ViewModels are created to flatten and select only the needed data properties. Automapper is introduced as a tool to automatically map between domain models and ViewModels to avoid tedious mapping code. It provides features like projection, value resolution, null substitution and configuration with a fluent API.
DevEX - reference for building teams, processes, and platforms
The ViewModel Pattern with AutoMapper for Flattening and Mapping Data
1. The ViewModel Pattern Simone ChiarettaArchitect, Council of the EU http://codeclimber.net.nz Twitter: @simonech June 23rd, 2010
2. Who the hell am I? Simone Chiaretta Microsoft MVP ASP.NET ASP Insider Blogger – http://codeclimber.net.nz ItalianALT.NET UG Founder OpenSource developer Climber All Around Nice Guy Disclaimer:"The viewsexpressed are purelythose of the speaker and may not in anycircumstancesberegarded as stating an official position of the Council"
4. Workflow of a MVC Application Controller asks for the data to the Model The request gets to the Controller Model 2 1 3 Controller Browser Model returns the data back to the Controller Controller formats data and sends them to the View View 4 5 View builds the page that is sent back to the Browser 3
5. Workflow of a MVC Application Controller asks for the DomainModel to the BLL The request gets to the Controller BLL 2 1 3 Controller Browser BLL returns the DomainModel to the Controller Controller formats DomainModelinto ViewModeland sends it to the View View 4 5 View builds the page that is sent back to the Browser 4
6. DomainModel != ViewModel DomainModel Data + Behaviours Hierarchical, complex types ViewModel Only Data Flat, only strings
12. Features Flattening Projection FluentAPIconfiguration Mapping of List and Collections Mapping of NestedObjects CustomTypeConverter CustomValueResolver CustomFormatters NullSubstitution
18. Rating If you liked this talk, please consider rating it: http://speakerrate.com/talks/3670-the-viewmodel-pattern 17 Disclaimer:"The viewsexpressed are purelythose of the speaker and may not in anycircumstancesberegarded as stating an official position of the Council"