Book Image

MVVM Survival Guide for Enterprise Architectures in Silverlight and WPF

By : Muhammad Shujaat Siddiqi, Ryan Vice
Book Image

MVVM Survival Guide for Enterprise Architectures in Silverlight and WPF

By: Muhammad Shujaat Siddiqi, Ryan Vice

Overview of this book

MVVM (Model View View Model) is a Microsoft best practices pattern for working in WPF and Silverlight that is highly recommended by both Microsoft and industry experts alike. This book will look at the reasons for the pattern still being slow to become an industry standard, addressing the pain points of MVVM. It will help Silverlight and WPF programmers get up and running quickly with this useful pattern.MVVM Survival Guide for Enterprise Architectures in Silverlight and WPF will help you to choose the best MVVM approach for your project while giving you the tools, techniques, and confidence that you will need to succeed. Implementing MVVM can be a challenge, and this book will walk you through the main issues you will come across when using the pattern in real world enterprise applications.This book will help you to improve your WPF and Silverlight application design, allowing you to tackle the many challenges in creating presentation architectures for enterprise applications. You will be given examples that show the strengths and weaknesses of each of the major patterns. The book then dives into a full 3 tier enterprise implementation of MVVM and takes you through the various options available and trade-offs for each approach. During your journey you will see how to satisfy all the demands of modern WPF and Silverlight enterprise applications including scalability, testability, extensibility, and blendability.Complete your transition from ASP.NET and WinForms to Silverlight and WPF by embracing the new tools of these platforms, and the new design style that they allow for. MVVM Survival Guide for Enterprise Architectures in Silverlight and WPF will get you up to speed and ready to take advantage of this powerful new presentation platform.
Table of Contents (21 chapters)
MVVM Survival Guide for Enterprise Architectures in Silverlight and WPF
Credits
Foreword
About the Authors
About the Reviewer
www.PacktPub.com
Preface
MVVM Frameworks
Index

Preface

MVVM (Model View View Model) is a Microsoft best practices pattern for working in WPF and Silverlight that is highly recommended by both Microsoft and industry experts alike. This book will look at the reasons for the pattern still being slow to become an industry standard, addressing the pain points of MVVM. It will help Silverlight and WPF programmers get up and running quickly with this useful pattern.

MVVM Survival Guide for Enterprise Architectures in Silverlight and WPF will help you to choose the best MVVM approach for your project while giving you the tools, techniques, and confidence that you will need to succeed. Implementing MVVM can be a challenge, and this book will walk you through the many issues you will come across when using the pattern in real world enterprise applications.

This book will help you to improve your WPF and Silverlight application design, allowing you to tackle the many challenges you will face in creating presentation architectures for enterprise applications. You will be given examples that show the strengths and weaknesses of each of the major presentation patterns. The book then dives into a full 3 tier enterprise implementation of MVVM and takes you through the various options available and the trade-offs for each approach. During your journey you will see how to satisfy many of the challenges of modern WPF and Silverlight enterprise applications including scalability, testability, and extensibility.

Complete your transition from ASP.NET and WinForms to Silverlight and WPF by embracing the new tools in the Silverlight and WPF platforms, and the new design style that they allow for. This book will get you up to speed and ready to take advantage of these powerful new presentation platforms.

What this book covers

Chapter 1, Presentation Patterns, gives the reader an example-driven overview of the history of presentation patterns. We will implement a Project Billing sample application using various approaches including MVC and MVP. Along the way, we will look at the issues with each pattern that motivated the next pattern in the evolutionary chain. This chapter also demonstrates how presentation patterns that require .NET events, such as MVC and MVP, can cause memory leaks if not properly implemented. This chapter will leave the reader with the knowledge needed to discuss the tradeoffs of the various presentation patterns and allow the reader to answer question like why use MVVM over MVP or MVC.

Chapter 2, Introduction to MVVM, covers the various features of WPF and Silverlight that make MVVM an attractive option on these platforms. We will follow this by re-implementing the Project Billing sample application from the first chapter using MVVM. We will then look at some of the benefits and cost of using MVVM. We will finish off the chapter by taking a quick look at the MVVM Light open source framework that will be used throughout the book.

Chapter 3, Northwind—Foundations, will walk through how to lay the foundation of the Northwind application that we will build over the next four chapters. We will wire up the Northwind database using Entity Framework and see how Entity Framework integrates with the binding systems in WPF and Silverlight to provide change notifications. We will also add unit tests that allow us to see how MVVM allows us to test all of our view logic.

Chapter 4, Northwind—Services and Persistence Ignorance, will have us attempting to make our application more scalable by adding a WCF service layer between the Presentation Layer and the Application Layer. We will see how WCF integrates with the binding system in both WPF and Silverlight to provide change notifications. We will also look at the benefits and cost of implementing a Persistence Ignorant Presentation Layer.

Chapter 5, Northwind—Commands and User Inputs, discusses the benefits of taking advantage of the commanding system in WPF and Silverlight to implement MVVM using the pure approach.

Chapter 6, Northwind —Hierarchical View Model and IoC, explains the power and productivity that can be added by using the Hierarchical View Model approach to MVVM. We will also see how to implement an Inversion of Control framework using IoC best practices by updating our application to use the Ninject for IoC framework.

Chapter 7, Dialogs and MVVM, discusses the various options for showing modal and modeless dialogs. It also discusses how data can be shared across the dialogs that we will create.

Chapter 8, Workflow-based MVVM Applications, explains how we can use Windows WF to control the flow of the user interface. It would also be touching the area of business rules validation using WF including the discussion about slow executing workflows.

Chapter 9, Validation, discusses the various techniques for data entry and business rules validation. The chapter will also be shedding some light on how the results of these validations can be displayed to the user.

Chapter 10, Using Non-MVVM Third-party Controls, will focus on the discussion regarding the usage of non-MVVM based controls in your MVVM based design to improve the testability of our code base.

Chapter 11, MVVM and Application Performance, explains some features of XAML frameworks targeting for better application performance.

Appendix A, MVVM Frameworks, outlines the basic features to look for before selecting an MVVM framework or toolkit. It also lists the available MVVM frameworks popular in the industry.

Appendix B, Binding at a Glance, summarizes the Binding System infrastructure, which makes MVVM possible in WPF and Silverlight.

What you need for this book

  • Microsoft Visual Studio 2010 Service Pack 1

  • Rhino Mocks

  • .NET Framework 4 Platform Update 1 for Chapter 8, Workflow-based MVVM Applications

Who this book is for

This book will be a valuable resource for Silverlight and WPF developers who want to fully maximize the tools with recommended best practices for enterprise development. This is an advanced book and you will need to be familiar with C#, the .NET framework, and Silverlight or WPF.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "You should now be able to execute ICustomerService.GetCustomers() from WCF Test Client."

A block of code is set as follows:

public class RepositoryRegistry : Registry
{
    public RepositoryRegistry()
    {
        For<IUIDataProvider>()
            .Singleton();
        For<ICustomerService>()
            .Singleton()
            .Use(() => new CustomerServiceClient());
    }
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

public class OrderViewModel : ViewModelBase
{
    public const string ModelPropertyName = "Model";
    private Order _model;
    public Customer Customer { get; set; }
    private readonly IToolManager _toolManager;exten =>i,1,Voicemail(s0)

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "This will add a Show Details link to our grid".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.