没有合适的资源?快使用搜索试试~ 我知道了~
首页Microsoft Prism 4开发者指南:构建WPF和Silverlight的模块化MVVM应用
Microsoft Prism 4开发者指南:构建WPF和Silverlight的模块化MVVM应用
4星 · 超过85%的资源 需积分: 9 13 下载量 190 浏览量
更新于2024-07-28
收藏 14.07MB PDF 举报
《微软普林斯4(开发者指南)》是一本详尽的指南,专为Windows Presentation Foundation (WPF) 和 Silverlight 开发者提供构建可扩展、模块化应用程序以及实现 Model-View-ViewModel (MVVM) 设计模式的工具和最佳实践。该指南覆盖了从基础入门到高级特性的广泛内容,旨在帮助开发者充分利用 Prism 框架提升软件开发效率和代码组织。
1. **概览**
- 指南结构丰富,包含多个章节,从简介开始,逐步深入,包括:
- **第1章:介绍** - 对Prism框架及其在MVVM架构中的作用进行概述。
- **第2章:初始化Prism应用** - 教导如何正确地设置和配置基于Prism的应用程序。
- **第3章:组件间的依赖管理** - 学习如何有效地处理应用内不同组件之间的依赖关系。
2. **模块化应用开发**
- **第4章** 探讨如何使用Prism构建模块化应用,以便于代码复用和维护。
3. **MVVM实践**
- **第5章** 提供MVVM模式的实现细节,包括视图、视图模型和命令的交互。
- **第6章:高级MVVM场景** - 包括更复杂的设计模式和解决方案,如命令分发器、事件总线等。
4. **用户界面设计**
- **第7章:UI组合** - 如何利用Prism来组织和管理用户界面组件,确保灵活性和一致性。
5. **导航与通信**
- **第8章:导航** - 描述如何在应用程序中实现流畅的导航功能,以及组件间的通信策略。
- **第9章:松耦合组件间通信** - 阐述如何在独立组件之间进行低耦合通信,提高代码的可重用性和可维护性。
6. **跨平台共享**
- **第10章:Silverlight和WPF代码共享** - 介绍如何在两种平台间共享代码,减少开发成本。
7. **部署与升级**
- **附录D:升级指导** - 提供从Prism 2.x版本及复合应用程序指导升级到4.0的步骤。
- **附录E:扩展Prism** - 讨论如何根据项目需求自定义或扩展框架的功能。
8. **参考实现**
- **附录F** 包含两个参考实现示例:StockTrader和MVVM参考实现,便于开发者学习和实践。
9. **文档附件**
- **附录A:术语表** - 解释专业术语,确保开发者对框架有清晰的理解。
- **附录B:Prism库模式** - 提供框架核心设计模式的详细描述。
- **附录G:快速开始** - 帮助新手快速上手Prism开发。
《微软普林斯4开发者指南》是一份全面的资源,涵盖了从框架安装到高级应用场景的方方面面,对于任何想要深入理解和使用Prism框架的开发者来说,是不可或缺的参考工具。
This section describes how to install Prism. It involves the following three steps:
1.
Install system requirements.
2.
Extract the Prism source code, binaries, and documentation.
3.
Register the Prism binaries.
Step 1: Install System Requirements
Prism was designed to run on the Microsoft Windows 7, Windows Vista, or Windows Server 2008 operating system.
This version has been smoke tested on Windows XP Professional and Windows Server 2003, but it has not been
exhaustively tested. WPF applications built using this guidance require the .NET Framework 4.0, and Silverlight
applications require Silverlight 4.
Before you can use the Prism Library, the following must be installed:
Microsoft .NET Framework 4.0 (installed with Visual Studio 2010)
Microsoft Visual Studio 2010 Professional, Premium, or Ultimate editions
Note:
Visual Studio 2010 Express Edition can be used to develop Prism applications using the Prism Library.
If you are developing Silverlight applications, the following must be installed:
Microsoft Silverlight 4 Tools for Visual Studio 2010 (required for Silverlight development; includes the developer
Silverlight runtime)
Note:
Although the Silverlight Tools for Visual Studio 2010 are not required, it is recommended for all WPF and Silverlight
developers to download and use the latest version of the Silverlight Tools for Visual Studio 2010.
The WPF and Silverlight Designer for Visual Studio is updated together with the Silverlight developer runtime and
software development kit (SDK), which are included in the download. These updates come in the form of new
features and bug fixes.
Optionally, you should consider also installing the following:
Microsoft Expression Blend 4. A professional design tool for creating compelling user experiences and applications
for WPF and Silverlight.
Windows Phone Developer Tools SDK. For Windows Phone 7 development.
Note:
For more information about using Prism on Windows Phone 7, see the Windows Phone 7 Developer Guide community
site on CodePlex (http://wp7guide.codeplex.com/.)
Step 2: Extract the Prism Source Code, Binaries, and Documentation
To install the Prism assets, right-click the Prismv4.exe file, and then click Run as administrator. This will extract the
source code, binaries, and documentation into the folder of your choice.
Step 3: Register the Prism Binaries
Registering the Prism Library with Visual Studio is not required, but doing so simplifies the task of referencing the Prism
Library assemblies in your projects. If you elect to register the binaries, they will be listed in the Visual Studio Add
References dialog box when adding a reference. If you elect to not register the binaries, you will need to manually set
a file reference to the Prism Library binaries in your projects. The Prism Library signed assemblies will be placed in the
following folders:
{prism}\Bin\Desktop
{prism}\Bin\Silverlight
{prism}\Bin\Phone
To register the Prism Library binaries, launch the RegisterPrismBinaries.bat batch file located in the folder where you
extracted Prism. This batch file creates a temporary .reg file with the information required to register the Desktop,
Silverlight, and Phone folders containing the binaries and uses it to update the registry. Because updating the registry
is a privileged operation, a User Account Control (UAC) prompt will appear if you do not have elevated privileges. For
additional information about UAC, see "What is User Account Control."
Note:
At most, one copy of the binaries can be registered using the script; if multiple copies of the Prism Library are
registered, only the binaries for the last registered copy will be available in Visual Studio.
Exploring Prism
What's New in This Release?
Page 16
This release of Prism has been updated to target WPF 4.0 and Silverlight 4, and it contains several areas of new and
significantly updated guidance, including the following:
Managed Extensibility Framework (MEF). Prism now includes guidance on using MEF to manage dependencies
and to maintain loose coupling between components. The use of MEF is explored in Chapter 3, "Managing
Dependencies Between Components."
The Model-View-View Model (MVVM) pattern. Previous versions of Prism have provided extensive guidance
on the use of separated presentation patterns. This guidance has now been updated to focus on the MVVM
pattern. Chapter 5 provides an overview of the MVVM pattern and describes how to implement it. Chapter 6
covers more advanced MVVM scenarios.
Navigation. Prism now provides guidance on implementing navigation within your WPF or Silverlight application.
This guidance covers both state-based navigation, which is used when you update the visual state of a single
view, and view-switching navigation, which is used when navigating between views. Both approaches are
covered in depth in Chapter 8, "Navigation."
Prism now also provides signed binary versions of the Prism Library assemblies. These assemblies are provided as a
convenience for developers who want to use the Prism Library in their own applications without modification. In
addition, all Visual Studio projects (for the Prism Library as well as the reference implementations and QuickStarts)
have also been migrated to use Visual Studio 2010 and Silverlight 4.
For a list of the new features, assets, and API changes, see What's New in Prism 4.0.
What's in the Box?
Prism consists of the following:
Prism Library source code. The source code for the Prism Library assemblies, including the core Prism
functionality, plus Unity and MEF extensions, which provide additional components for using Prism with the Unity
Application Block (Unity) and the Managed Extensibility Framework.
Prism binary assemblies. Signed binary versions of the Prism Library assemblies. These assemblies are located
in the bin folder and are provided as a convenient way for developers to use the Prism Library. The Prism binaries
can be rebuilt and can be registered with Visual Studio using the provided script files. The binary assemblies also
include the Unity Application Block and the Service Locator assemblies.
Reference implementations. Comprehensive sample applications that illustrate how Prism can be used to
implement real-world application scenarios. The reference implementations are intentionally incomplete, but they
illustrate how many of the patterns in Prism can work together within a single application. Prism provides two
reference implementations: the Stock Trader Reference Implementation (Stock Trader RI) and the MVVM
Reference Implementation (MVVM RI).
QuickStarts. Prism includes the source code for several small, focused sample applications that illustrate the
MVVM pattern, navigation, UI composition, modularity, commanding, event aggregation, and multi-targeting.
Documentation. The Prism 4 documentation provides an overview of the goals and concepts behind Prism and
detailed guidance on using each of the capabilities and design patterns provided by Prism. The next section
provides a chapter-by-chapter overview of the topics covered.
Exploring the Documentation
The Prism documentation spans a wide range of topics, including an overview of common development challenges and
the composite application approach, an overview of the Prism Library and the design patterns that it implements, as
well as step-by-step instructions for using the Prism Library during development. The documentation is intended to
appeal to a broad technical audience to help the reader to understand and use Prism within their own applications. The
documentation includes the following:
Chapter 2, "Initializing Prism Applications." This chapter discusses what needs to happen to get a modular Prism
application up and running.
Chapter 3, "Managing Dependencies Between Components." Applications based on the Prism Library rely on a
dependency injection container. Although Prism has the ability to work with nearly any dependency injection
container, the Prism Library provides two default options for dependency injection containers: Unity or MEF. This
chapter discusses the different capabilities and what you need to think about when working with a dependency
injection container.
Chapter 4, "Modular Application Development." This chapter discusses the core concepts, key decisions, and
core scenarios when you create a modular client application with Prism.
Chapter 5, "Implementing the MVVM Pattern." Using the MVVM pattern, you separate the UI of your application
and the underlying presentation and business logic into three separate classes: the view, model, and view
model. This chapter discusses the core concepts behind the MVVM pattern and describes how to implement it in
your application using Prism.
Chapter 6, "Advanced MVVM Scenarios." This chapter provides guidance on implementing more advanced
scenarios using the MVVM pattern, including how to implement composite commands (commands that represent
a group of commands), and how to handle asynchronous web service and user interactions. This chapter also
provides guidance on using a dependency injection container, such as Unity or MEF, to handle the construction
Page 17
and wire-up of the MVVM classes.
Chapter 7, "Composing the User Interface". Regions are placeholders that allow a developer to specify where
views will be displayed in the application's UI. In Prism, there are two approaches to displaying views in a region:
view discovery and view injection. This chapter describes how to work with regions and the UI. It also includes
information for UI designers to understand composite applications.
Chapter 8, "Navigation." Navigation is the process by which the application coordinates changes to its UI as a
result of the user's interaction with the application or internal application state changes. This chapter provides
guidance on implementing state-based navigation, where the state of the UI in a view is updated to reflect
navigation, and view-switching navigation, where a new view is created and displayed in a region.
Chapter 9, "Communicating Between Loosely Coupled Components." This chapter discusses the various options
for communicating between components in different modules, using commanding, the EventAggregator, region
context, and shared services.
Chapter 10, "Sharing Code Between Silverlight and WPF." Multi-targeted code is targeting two different platforms
with largely the same code base. In this case, the technologies that this topic describes are WPF and Silverlight.
This chapter helps you understand what multi-targeting is and its advantages and disadvantages. Prism provides
the Project Linker tool to help you to automatically create and maintain links from a source project to a target
project to share code that is common between Silverlight and WPF.
Chapter 11, "Deploying Prism Applications." This chapter addresses deployment considerations for Prism WPF and
Silverlight applications.
Appendix A, "Glossary." This appendix provides a concise summary of the terms, concepts, design patterns and
capabilities provided by Prism.
Appendix B, "Patterns in the Prism Library." This appendix describes the software design patterns applied in the
Prism Library and the Stock Trader RI. This topic primarily targets architects and developers wanting to
familiarize themselves with the patterns used to address the challenges in building composite applications.
Appendix C, "Prism Library." This appendix provides an overview of the Prism Library.
The following topics are included with the source code and online:
Appendix D, "Upgrading from Previous Versions."This appendix discusses what you need to know if you are
upgrading from previous versions of Prism.
Appendix E, "Extending Prism." This appendix discusses how you can extend Prism modularity, behaviors, and
navigation.
Appendix F, "Reference Implementations." This appendix describes the reference implementations included with
Prism. For more information, see the section "Exploring the Reference Implementations."
Appendix G, "QuickStarts." Prism includes the source code for several QuickStarts that demonstrate key
concepts. For more information, see the next section, "Exploring the QuickStarts."
Appendix H, "Prism Hands-On Labs." The hands-on labs demonstrate building a simple composite application,
step-by-step, in WPF and Silverlight. This appendix primarily targets developers who want to understand the
basic concepts of the Prism Library. It also includes a deployment hands-on lab for publishing and updating a
Prism WPF application with ClickOnce.
Exploring the QuickStarts
The QuickStarts are small, focused applications that illustrate specific Prism-related concepts. QuickStarts are an ideal
starting point if you want to gain an understanding of a key concept and you are comfortable learning new techniques
by examining source code. Prism includes the following QuickStarts:
Modularity QuickStarts for WPF and Modularity QuickStarts for Silverlight. These QuickStarts demonstrate how to
build WPF and Silverlight applications composed of modules. The modules can be statically loaded, when the shell
contains a reference to the module's assembly, or dynamically loaded, when modules are dynamically discovered
and loaded at run time. The QuickStarts demonstrate using the Unity container and MEF.
Basic MVVM QuickStart and MVVM QuickStart. The Basic MVVM QuickStart demonstrates how to build a very
simple application that implements the MVVM presentation pattern. The MVVM QuickStart demonstrates how to
build an application that implements the MVVM presentation pattern, showing some of the more common
challenges that developers can face, such as validation, UI interactions, and data templates.
UI Composition QuickStart. This QuickStart demonstrates how to build WPF and Silverlight UIs composed of
different views that are dynamically loaded into regions and that interact with each other in a decoupled way. It
illustrates how to use both the view discovery and view injection approaches for UI composition.
State-Based Navigation QuickStart. This QuickStart demonstrates an approach to define the navigation of a
simple application. The approach used in this QuickStart uses the Silverlight Visual State Manager (VSM) to
define the different states that the application has and defines animations for both the states and the
transitions between states.
View-Switching Navigation QuickStart. This QuickStart demonstrates how to use the Prism Region Navigation
API. The QuickStart shows multiple navigation scenarios, including navigating to a view in a region, navigating to
a view in a region contained in another view (nested navigation), navigation journal support, just-in-time view
creation, passing contextual information when navigating to a view, views and view models participating in
navigation, and using navigation as part of an application built through modularity and UI composition.
Page 18
Commanding QuickStart. This QuickStart demonstrates how to build a WPF or Silverlight UI that uses commands
provided by the Prism Library to handle UI actions in a decoupled way.
Event Aggregation QuickStart. This QuickStart demonstrates how to build a WPF or Silverlight application that
uses the Event Aggregator service. This service enables you to establish loosely coupled communications
between components in your application.
Multi-Targeting QuickStart. This QuickStart demonstrates the structure of a project created to multi-target WPF
and Silverlight environments. It provides a desktop experience (on WPF) and a Rich Internet Application (RIA)
experience (on Silverlight).
Exploring the Reference Implementations
The Prism reference implementations are example applications based on real-world challenges customers are facing.
When you look at these applications, look at them as a reference for building applications with the Prism Library. The
Prism reference implementations include:
Stock Trader Reference Implementation. The Stock Trader RI is a composite application that demonstrates an
implementation of the baseline architecture using the Prism Library.
MVVM Reference Implementation. The MVVM RI demonstrates complex challenges that developers face when
creating applications using the MVVM pattern.
Upgrading from Earlier Releases
If you are upgrading from the previous releases of this guidance, you should review "Upgrading from Previous Releases"
in Appendix D to understand the major differences between this and the previous releases.
If you are upgrading from the Composite UI Application Block (which targeted WinForms) to the Prism Library, you
should review "Upgrading from the Composite UI Application Block" in Appendix D so that you understand how the
concepts in the Composite UI Application Block map to the Prism Library.
An Overview of Prism
Prism Design Goals
Prism was designed to help you design and build rich, flexible, and easy-to-maintain WPF and Silverlight applications.
The Prism Library implements design patterns that embody important architectural design principles, such as separation
of concerns and loose coupling. Using the design patterns and capabilities provided by the Prism Library, you can
design and build applications using loosely coupled components that can evolve independently but that can be easily
and seamlessly integrated into the overall application.
Prism is designed around the core architectural design principles of separation of concerns and loose coupling. This
allows Prism to provide many benefits, including the following:
Reuse. Prism promotes reuse by allowing components and services to be easily developed, tested and
integrated into one or more applications. Reuse can be achieved at the component level through the reuse of
unit-tested components that can be easily discovered and integrated at run time through dependency injection,
and at the application level through the use of modules that encapsulate application-level capabilities that can
be reused across applications.
Extensibility. Prism helps to create applications that are easy to extend by managing component dependencies,
allowing components to be more easily integrated or replaced with alternative implementations at run time, and
by providing the ability to decompose an application into modules that can be independently updated and
deployed. Many of the components in the Prism Library itself can also be extended or replaced.
Flexibility. Prism helps to create flexible applications by allowing them to be more easily updated as new
capabilities are developed and integrated. Prism also allows WPF and Silverlight applications to be developed
using common services and components, allowing the application to be deployed and consumed in the most
appropriate way. It also allows applications to provide different experiences based on role or configuration.
Team Development. Prism promotes team development by allowing separate teams to develop and even deploy
different parts of the application independently. Prism helps to minimize cross-team dependencies and allows
teams to focus on different functional areas (such as UI design, business logic implementation, and
infrastructure code development), or on different business-level functional areas (such as profile, sales,
inventory, or logistics).
Quality. Prism can help to increase the quality of applications by allowing common services and components to
be fully tested and made available to the development teams. In addition, by providing fully tested
implementations of common design patterns, and the guidance needed to fully leverage them, Prism allows
development teams to focus on their application requirements instead of implementing and testing infrastructure
code.
It is important to note that Prism was designed so that you can use any of Prism's capabilities and design patterns
individually, or all together, depending on your requirements and your application scenario. Prism was designed so that
it could be incrementally adopted, allowing you to use the capabilities and design patterns that make sense for your
particular application without requiring major structural changes.
Page 19
Finally, because software testing should be considered a first-class development activity and tightly integrated into
the development process, Prism provides extensive support for various types of software testing, thereby allowing you
to design and build applications that are easy to test. Prism itself was developed with testing in mind. It was
developed to meet multiple strict quality gates to ensure that it meets Microsoft security standards and that it will
function correctly on multiple operating systems, with multiple versions of Visual Studio, and with multiple programming
languages. Unit tests were run after each check-in. In addition, the Prism library was tested against several additional
quality gates, as listed in the following table.
Test
Description
Acceptance Testing
Validates the application functionality using user
scenarios to drive the test requirements. Tests can be
executed manually or automated.
Application Building Exercises
Team members build applications consuming the
deliverable software.
Black Box Testing
Manual acceptance tests perform from the user point of
view.
Cross Browser Testing
All automated tests are run on multiple browsers.
Cross Platform Testing
All automated tests are run on multiple platforms.
Globalization Testing
All automated tests are run on multiple languages.
Performance Testing
Measures how fast a particular aspect of a system
performs under-load.
Security Review
Internal Microsoft security audit standards that cover
thread models, identifying attack factors and running the
code though security analysis tools.
Stress Testing
Measures stability of the system under extreme loads;
specifically looking to drive out issues like memory leaks
and threading issues.
White Box Testing
In-depth source code analysis validating the coding
standards, structure and how it maps to the overall
architecture.
The Prism Library source code includes unit and UI automation tests, as shown in the following table. You can use
these as an educational resource, or you can run the tests against the Prism Library itself. This allows you to
customize, re-compile, test and deploy a modified version of the Prism Library using similar quality gates as the Prism
team.
Test
Description
UI Automation Tests
Limited range of acceptance testing; driving the
application from the user perspective
Unit Tests
Validates the implementation of a class
Prism Key Concepts
Prism provides capabilities and design patterns that may be unfamiliar to you, especially if you're new to design
patterns and composite application development. This section provides a brief overview of the main concepts behind
Prism and defines some of the terminology that you will see used throughout the documentation and code.
Modules. Modules are packages of functionality that can be independently developed, tested, and (optionally)
deployed. In many situations, modules are developed and maintained by separate teams. A typical Prism
application is built from multiple modules. Modules can be used to represent specific business-related
functionality (for example, profile management) and encapsulate all the views, services, and data models
required to implement that functionality. Modules can also be used to encapsulate common application
infrastructure or services (for example, logging and exception management services) that can be reused across
multiple applications.
Module catalog. In a composite application, modules must be discovered and loaded at run time by the host
application. In Prism, a module catalog is used to specify which modules to are to be loaded, when they are
loaded, and in what order. The module catalog is used by the ModuleManager and ModuleLoader
components, which are responsible for downloading the modules if they are remote, loading the module's
assemblies into the application domain, and for initializing the module. Prism allows the module catalog to be
specified in different ways, including programmatically using code, declaratively using XAML, or using a
configuration file. You can also implement a custom module catalog if you need to.
Page 20
剩余341页未读,继续阅读
114 浏览量
119 浏览量
2011-04-01 上传
361 浏览量
112 浏览量
212 浏览量
2011-10-26 上传
citywalker007
- 粉丝: 26
- 资源: 72
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功