advanced topics for building large-scale applications with microsoft silverlight
DESCRIPTION
CL22. Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight. John Papa Senior Technical Evangelist Microsoft Corporation. Outline. MVVM Model – View – ViewModel What it does Where it works well Variations Prism Enabling MVVM Filling the gaps Options. Goals. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/1.jpg)
Advanced Topics for Building Large-Scale Applications with Microsoft SilverlightJohn PapaSenior Technical EvangelistMicrosoft Corporation
CL22
![Page 2: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/2.jpg)
Outline> MVVM
> Model – View – ViewModel> What it does> Where it works well> Variations
> Prism> Enabling MVVM> Filling the gaps> Options
![Page 3: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/3.jpg)
Goals> Understand MVVM’s Role in Silverlight
> Many ways to accomplish your goal> See it in Action> Learn about MVVM Enablers
> Prism> Roll Your Own
![Page 4: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/4.jpg)
Another MC_ Acronym?> MVVM> MVC> MVP> MV????
> Commonly accepted patterns for maintainable, scalable applications
![Page 5: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/5.jpg)
MVVMThe What and Why> Separation of concerns> View = handles UI> Model = contains the pure data > ViewModel = communicates between
View and Model through bindings> Works GREAT for Silverlight and WPF
> XAML based data bindings> Testable
![Page 6: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/6.jpg)
The MVVM TriadPutting it Together
ViewModel
View
Model
> Display data in Controls
> UI Friendly Entities, UI State, Actions
> Entities representing data
![Page 7: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/7.jpg)
ModelMVVM> Represents the data> The entity> Not required to know where it gets its
data from> From a WCF service. WCF RIA Services,
etc> May contain validation
![Page 8: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/8.jpg)
ViewMVVM> The screen, the UI, the UserControl in
Silverlight> Handles UI look and feel> Presentation of information> Communicates with ViewModel
through bindings
![Page 9: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/9.jpg)
ViewModelMVVM> Main source of logic for the MVVM triad> Connects the Model to the View> Abstracts the View> Public properties that are bound to a View> INotifyPropertyChanged and
INotifyCollectionChanged talk to the View through bindings
> Listens for changes from the View through bindings
> Invokes services to communicate outside the MVVM triad
![Page 10: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/10.jpg)
Which Way Do I Go?MVVM Variations> View must be paired with a ViewModel
somehow> Several workable options> Maintain the spirit of each of the
components of the MVVM triad
![Page 11: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/11.jpg)
View First MVVM Variations> ViewModel is declared as a Static
Resource in the View’s XAML> Works well in Expression Blend
> Another way is to create ViewModel in the View’s code-behind
![Page 12: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/12.jpg)
View First MVVM
demo
![Page 13: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/13.jpg)
ViewModel FirstMVVM Variations> View is injected into the ViewModel’s
constructor > Example:
> ViewModel is created then the View is created using Dependency Injection
![Page 14: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/14.jpg)
View and ViewModel MarriageMVVM Variations> View must be paired with a ViewModel
somehow> ViewModel and View are created
through an intermediary, then paired together
![Page 15: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/15.jpg)
Marrying the View to the ViewModelvm = new MyVM();view = new MyView();view.DataContext = vm;
// With Unityvm = container.Resolve<IMyVM>();view = container.Resolve<MyView>();
view.DataContext = vm;
![Page 16: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/16.jpg)
Prism 2Be Picky> Prism is a set of options> Use what you want and ignore the rest
> Example: > Choose Modules and Commanding, but ignore
Event Aggregation and Regions
![Page 17: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/17.jpg)
Prism Technical Concepts
Container
Commands
Bootstrapper
Regions
Modules
Event Aggregation
Unity and DI
Shell
![Page 18: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/18.jpg)
BootstrapperLet’s Get this Party Started!> Kicks off the application> Starts the main UI container (the
Shell)> Registers Modules and loads, if
needed> Registers any global singletons
(optional)> Usually contained in the “Bootstrapper
project”
![Page 19: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/19.jpg)
ShellThe Main View> The main UI container> Houses all of the Views that will be
loaded> Can be split into Regions> Knows nothing of what will be loaded
into it
![Page 20: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/20.jpg)
RegionsContent Areas > Area(s) in the Shell where Views can
be placed> Given a name> Can contain context, if needed> RegionManager exists to help
maintain Regions
![Page 21: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/21.jpg)
ModularitySelf Contained Modules> To the user this is seamless> Developed separately> Do not reference other modules> Solution is split into Modules > Example:
> City government application> Module 1: Managing land parcels> Module 2: Traffic light administration> Module 4: City Parks
> Modules share infrastructure and Models
![Page 22: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/22.jpg)
Dependency InjectionUsing Unity> Unity or other DI Tools (Ninject)> Testability and mocking> Abstraction
> Container object allows classes to be registered against their interfaces
> When an interface is requested, the container creates the class registered with the interface
> Supports singletons, too
![Page 23: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/23.jpg)
Register the Interface to the Class
container.RegisterType<IMyViewModel,
MyViewModel>();
![Page 24: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/24.jpg)
Create the Concrete Class
container.Resolve<IMyViewModel>();
![Page 25: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/25.jpg)
InfrastructureCommon Tools> A Silverlight class library project> Contains shareable items for the
modules> Classes> Assets> Resources
> Makes no references> A pure library
![Page 26: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/26.jpg)
CommandingActions and Reactions> Allows events between a View and a
ViewModel through Data Binding> ViewModel declares the Command
receiver> Command is declarative in XAML
> Button - Click> ListBox (Selector) – Selected
> Command is data bound to the ViewModel’s command receiver
> Can be disabled/enabled based on rules
![Page 27: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/27.jpg)
Event AggregatorPublisher and Subscriber > Allows events of any kind to be
published and subscribed to> Can be cross module> Can be filtered by subscribers> For example:
1. Click on a menu item in the Shell2. Event is invoked by the publisher3. Event is received by the subscriber4. The subscriber then loads a View in a
Region in the Shell
![Page 28: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/28.jpg)
InfrastructureCommon Tools> Infrastructure is a Silverlight class
library project> Contains classes, assets, resources
that are shared amongst the Modules> Does not reference any modules> Does not make calls to web services> It’s a pure library
![Page 29: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/29.jpg)
Modular MVVM and Prism
demo
![Page 30: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/30.jpg)
Screen Presentation EnablerEnabling Screens> Must be able to navigate between
screens> Views do not know about each other> Roll Your Own Screen Conductor
> Loading/unloading> Displaying/hiding> Can I Leave?> Clean yourself up!
![Page 31: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/31.jpg)
Screen Presentation FrameworkKey Players> Screen
> Manages the MVVM triad> ScreenFactory
> Creates a Screen class> ScreenFactoryRegistry
> A ScreenFactory directory> ScreenConductor
> Listens for & acts upon screen activation events
> ScreenCollection> Collects screens
![Page 32: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/32.jpg)
Screen Conductor
demo
![Page 33: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/33.jpg)
Resources> My blog: http://www.johnpapa.net > Twitter: @john_papa
> Prism from Patterns and Practices > http://www.codeplex.com/prism
> Article on the Screen Presentation Framework, MVVM and Prism > Coming soon to MSDN Online
![Page 34: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/34.jpg)
YOUR FEEDBACK IS IMPORTANT TO US! Please fill out session evaluation
forms online atMicrosoftPDC.com
![Page 35: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/35.jpg)
Learn More On Channel 9> Expand your PDC experience through
Channel 9
> Explore videos, hands-on labs, sample code and demos through the new Channel 9 training courses
channel9.msdn.com/learnBuilt by Developers for Developers….
![Page 36: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/36.jpg)
© 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.
![Page 37: Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight](https://reader036.vdocuments.us/reader036/viewer/2022062301/568162a0550346895dd31659/html5/thumbnails/37.jpg)