230 likes | 350 Views
Architecting Silverlight Applications with MVVM . Shawn Wildermuth President AgiliTrain Session Code: WIA301 . The Problem. The Problem (2). Tight Coupling Adds Complexity Simple Changes Cascade Difficult to Test Difficult to Develop Large Applications. Separation of Concerns.
E N D
Architecting Silverlight Applications with MVVM Shawn Wildermuth President AgiliTrain Session Code: WIA301
The Problem (2) • Tight Coupling • Adds Complexity • Simple Changes Cascade • Difficult to Test • Difficult to Develop Large Applications
Separation of Concerns • Loose Coupling • Layers are Individually Responsible • Established Patterns • Lessens the Need to Reinvent Architecture
Patterns • Model-View-Controller • Model-View-Presenter • Model-View-ViewModel
Patterns (2) • XAML is Declarative • Allows for Code-less Views • Older Patterns Don’t Fit
Model-View-ViewModel Model View-Model View
Model-View-ViewModel (2) Silverlight XAML View C#/VB ViewModel Model Internet Server C#/VB Services
Building the MVVM • Planning on MVVM • Build in Tiers • Plan for Testing
Building the MVVM (2) • The Model • Expose Data as Collections • Expose Methods for Different Data Shaping • More than one ViewModel May Use a single Model • Build Interface Providing Data • Allows Mocking of the Database if necessary • Eliminate Tight Coupling of Services with Model
demo The Model
Building the MVVM (4) • The ViewModel • Expose API that the View Needs • Use the Model to Provide the Data
demo The ViewModel
Building the MVVM (6) • The View • Declarative UI • Use as Much XAML as Possible • Don’t Write Code to Rebind Data • Perfect View is Code-less • In Silverlight 3 Behaviors and Element Binding Help
demo The View
Evolving Pattern • MVVM is Still Growing • Some Frameworks Support it (e.g. Prism) • Philosophy of Specifics is not settled • View-Centric • ViewModel-Centric • Marriage/Mediator • No Completely Right/Wrong Way to Implement It • Patterns Only Good If They Help
Frameworks • I Hand-Coded MVVM • Frameworks Help • Laurent Bugnion’s Light MVVM • http://www.galasoft.ch/mvvm/getstarted/ • Nikhilk Kothari’s FX Framework • http://projects.nikhilk.net/SilverlightFX • Michael Sync’s Silverlight MVVM Toolkit • http://silverlightmvvm.codeplex.com/
Resources • www.microsoft.com/teched Sessions On-Demand & Community • www.microsoft.com/learning • Microsoft Certification & Training Resources • http://microsoft.com/technet • Resources for IT Professionals • http://microsoft.com/msdn Resources for Developers
Complete an evaluation on CommNet and enter to win an Xbox 360 Elite!
Required Slide © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.