logo资料库

Building Enterprise Applications with WPF and the MVVM Pattern.p....pdf

第1页 / 共225页
第2页 / 共225页
第3页 / 共225页
第4页 / 共225页
第5页 / 共225页
第6页 / 共225页
第7页 / 共225页
第8页 / 共225页
资料共225页,剩余部分请下载后查看
Table of Contents
Introduction
Conventions and Features in This Book
Acknowledgments
Errata and Book Support
Chapter 1. Introduction to Model View ViewModel and Line of Business Applications
The Model View ViewModel Pattern
Line of Business Applications
Choosing the Right Technology
Silverlight or WPF?
Microsoft’s UI-Building Tools
Composition of a LOB User Interface
The Menubar
The Toolbar
The Tooltip (and Its Abuse)
Notifications and Alerts
The Ribbon Bar
General Style and Control Considerations
Separation of Concerns
Layers, Tiers, and Services
Summary
Chapter 2. Design Patterns
An Overview of Design Patterns
Classifying Design Patterns
UI Design Patterns
The MVC Pattern
The MVP Pattern
The PM Pattern and MVVM
Advanced Design Patterns and Techniques
The Inversion of Control Pattern
DSLs: Writing Fluent Code
Introduction to TDD
Summary
Chapter 3. The Domain Model
Introduction to Domain-Driven Design
DDD Terminology
Analyzing the CRM Domain
Domain Entity and Data Transfer Object
The POCO Object and the O/RM
Development Approaches of a Domain
Transaction Script
Database-Driven Approach
Domain-Driven Approach
How To Create an Object In DDD
Factory Patterns
Domain Entities Validation
Classic Validation
Validation Using Attributes and Data Annotations
Available Validation Frameworks
Unit Test the Domain Model
Sample Code: The CRM Domain Model
The Person Context
The Order Domain
Summary
Chapter 4. The Data Access Layer
Introduction
The Database and Stored Procedures
Choosing an O/RM
Microsoft Entity Framework
NHibernate
Other O/RMs for .NET
The Unit of Work
Lifecycle of a UoW
Identify a Business Transaction
The Repository Pattern
Test-Driven Development: The Data Layer
Building a Distributed Data Layer with RIA and WCF
Sample Code: The CRM Data Access Layer
A Flexible IUnitOfWork Interface
Mapping the Domain Model Using Entity Framework
Mapping the Domain Using NHibernate
Getting the Tools
The UnitOfWork and the ISession
Summary
Chapter 5. The Business Layer
Introduction
A Business Rule Is Not a Validation Rule
Business Rules by Service
The Facade Pattern
Business Rules by Workflow with WF 4.0
Different Ways of Running a Workflow
Third-Party Toolkits
Technologies for the Data Validation
Rule Engine and Business Rule Engine
Business Layer Considerations
When Do I Need to Create a Business Layer?
Bad BLL Habits
Sample Code: The Business Service Layer
Data Validation with the Enterprise Library 5.0
A Generic Workflow Engine
Service for Business Transactions
Summary
Chapter 6. The UI Layer with MVVM
Introduction to the MVVM Pattern
The View
Blendability: A Dummy ViewModel
The Model
The Command in WPF and Silverlight
A Workaround: An MVVM Command
Re-evaluate ICommand Execution
The ViewModel
The INotifyPropertyChanged Interface
The IDataErrorInfo Interface
DataTemplate in WPF and Silverlight
DataTemplate and MVVM
WeakEvents and Messages
The WeakEvent Pattern
The EventAggregator Pattern
Dialogs and Modal Pop-Ups
Modal View in MVVM
Inversion of Control with MVVM
Sample Code
The Microsoft Office Ribbon and MVVM
Summary
Chapter 7. MVVM Frameworks and Toolkits
MVVM Toolkits
MVVM Light Toolkit, by Laurent Bugnion
MEFedMVVM
Cinch, by Sacha Barber
MVVM and XAML Facilities
Karl Shifflett’s Tools
Radical, by Mauro Servienti
Composite UI Frameworks
Microsoft Prism
Caliburn
Index
About the Author
骂歹 Enterprise with Applications Building Windows·Presentation Fou ndat1on and the Model View ViewModel Pattern Raffaele Garofalo
Building Enterprise Applications with Windows® Presentation Foundation and the Model View ViewModel Pattern Raffaele Garofalo
Published with the authorization of Microsoft Corporation by: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, California 95472 Copyright © 2011 Raffaele Garofalo. Complying with all applicable copyright laws is the responsibility of the user. All rights reserved. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without express written permission of O’Reilly Media, Inc. Printed and bound in the United States of America. 1 2 3 4 5 6 7 8 9 LSI 6 5 4 3 2 1 Microsoft Press titles may be purchased for educational, business or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com. Visit our website at microsoftpress.oreilly.com. Send comments to mspinput@microsoft.com. Microsoft, Microsoft Press, ActiveX, Excel, FrontPage, Internet Explorer, PowerPoint, SharePoint, Webdings, Windows, and Windows 7 are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Other product and company names mentioned herein may be the trademarks of their respective owners. Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious, and no association with any real company, organization, prod- uct, domain name, e-mail address, logo, person, place, or event is intended or should be inferred. This book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the author, O’Reilly Media, Inc., Microsoft Corporation, nor their respective resellers or distributors, will be held liable for any damages caused or alleged to be caused either directly or indirectly by such information. Acquisitions and Development Editor: Russell Jones Production Editor: Kristen Borg Production Services: Octal Publishing, Inc. Technical Reviewer: David Hill Indexing: Fred Brown Cover: Karen Montgomery Illustrator: Robert Romano 978-0-735-65092-3
To my wife Deborah. Thank you for everything!
Contents at a Glance 1 Introduction to Model View ViewModel and Line of Business Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 Design Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 The Domain Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 3 The Data Access Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 4 The Business Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 5 6 The UI Layer with MVVM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 7 MVVM Frameworks and Toolkits . . . . . . . . . . . . . . . . . . . . . . 179 v
Table of Contents 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xi Conventions and Features in This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xviii Errata and Book Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xix Introduction to Model View ViewModel and Line of Business Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 The Model View ViewModel Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Line of Business Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Choosing the Right Technology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Silverlight or WPF? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Microsoft’s UI-Building Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Composition of a LOB User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 The Menubar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 The Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 The Tooltip (and Its Abuse) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Notifications and Alerts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 The Ribbon Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 General Style and Control Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Separation of Concerns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Layers, Tiers, and Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 2 Design Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 An Overview of Design Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Classifying Design Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 UI Design Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 The MVC Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 The MVP Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 The PM Pattern and MVVM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Advanced Design Patterns and Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 The Inversion of Control Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 DSLs: Writing Fluent Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Introduction to TDD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 vii
分享到:
收藏