Developers Guide to Microsoft Prism 4: Building Modular MVVM Applications using Windows Presentation Foundation and Microsoft Silverlight
Bob Brumfield
Geoff Cox
David Hill
Brian Noyes
Michael Puleio
Karl Shifflett
Copyright 2011
This document is provided as-is. Information and views expressed in this document, including URL and other Internet Web site references, may change without notice. You bear the risk of using it. Some examples depicted herein are provided for illustration only and are fictitious. No real association or connection is intended or should be inferred.
All rights reserved.
Microsoft, Windows, Windows Server, Windows Vista, Silverlight, Expression Blend, MSDN, IntelliSense, Visual C#, Visual C++, and Visual Studio are trademarks of the Microsoft group of companies.
All other trademarks are the property of their respective owners.
Microsoft Press
Foreword
What comes after Hello, World?
WPF and Silverlight developers are blessed with an abundance of excellent books, videos, and online articles from which to learn how to build a single screen application. These resources teach data binding, dependency properties, resources, styles, effects, control templating, and many other fundamentals of XAML platform programming. Theres no lack of tutorials on Model-View-ViewModel (MVVM), the justly popular and predominant pattern for structuring an individual screen. But they stop short of the guidance you need to deliver a non-trivial application in full.
Your first screen goes well. You add a second screen and a third. Because you started your solution with the built-in Navigation Application Template, adding new screens feels like hanging shirts on a closet rod. You are on a roll. Until the harsh reality of real application requirements sets in.
As it happens, your application has 30 screens not three. Theres no room on that closet rod for 30 screens. Some screens are modal pop-ups; you dont navigate to a pop-up. Screens become interdependent such that user activity in one screen triggers changes that propagate throughout the UI. Some screens are optional; others are visible only to authorized users. Some screens are permanent, while other screens can be opened and closed at will. You discover that navigating back to a previously displayed screen creates a new instance. Thats not what you expected and, to your horror, the prior instance is gone along with the users unsaved changes.
You realize that the out-of-the-box navigation is useless to you. You are resigned to ripping it out and starting over. You consider building your own UI framework, but decide to survey the scene first. Surely someone has been down this road before. Surely someone has published guidance and code to cope with the scale, variety, and complexity of your real world application.
Someone has. The Microsoft Prism Library, code samples, and the book that youre reading now are the culmination of a five year quest to consolidate the best advice and techniques from experts and practitioners in the field.
Prism covers all of the scenarios just mentioned and many more. Youll find guidance and supporting code for:
Partitioning the application into modules, those semi-autonomous islands of functionality that should be developed and maintained independently.
Mechanisms for loading modules asynchronously or on-demand so that applications start quickly.
A publish/subscribe apparatus, the event aggregator, for passing messages among components that cannot and should not connect directly.
Dynamically composing a complex screen, such as a dashboard, from several simpler views.
Creating pages using View-First, ViewModel-First, or a controller that makes them and coordinates them.
Initializing views with parameters or context information as when launching an editor that targets a selected customer.
Guidelines and examples of automated tests for views and view models that depend upon asynchronous data sources.
Many developers will see in Prism an all-in-one solution from a single trusted source. They have neither the time nor inclination to scrutinize each component, compare it with competitors, and assemble a custom framework from a buffet of alternatives. They fear the Franken-framework of mismatched parts from multiple vendors. For this audience, Prism is a safe and reliable choice. I dont know of a solution as comprehensive, well documented, or well supported. The design is sound. The code is solid and tested. Great applications are built exclusively with Prism and yours can be one of them.