1: Introduction To The Prism Library 5.0 For WPF: #!155chartopicsummary!#
1: Introduction To The Prism Library 5.0 For WPF: #!155chartopicsummary!#
challenges you might encounter when building WPF client applications, and
describes how Prism helps you to address those challenges.
In this type of application, the user can be presented with a rich and flexible user
experience that provides a task-oriented focus over functionality that spans multiple
back-end systems, services, and data stores, where each is represented by one or
more dedicated modules. The clean separation between the application logic and
In this case, the composite application allows the UI to be dynamic composed. This
delivers a flexible user experience. For example, it can allow new functionality to be
dynamically added to the application at run time, which enables rich end-user
customization and extensibility.
Application performance
Application versioning
Error handling and fault tolerance
Prerequisites
Prism assumes you have hands-on experience with WPF . There are a few important
concepts that Prism uses heavily, and you should become familiar with them. They
include the following:
Resources. These are how styles, data templates, and control templates
are created and managed in WPF.
Commands. These are how user gestures and input are connected to
controls.
An Overview of Prism
Architectural Goals
The guidance is designed to help architects and developers achieve the following
objectives:
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.
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
Globalization Testing
Performance Testing
Security Review
Stress Testing
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
Unit Tests
designed to work with Unity or MEF, or with any other dependency injection
containers via the ServiceLocator.
Services. Services are components that encapsulate non-UI related
functionality, such as logging, exception management, and data access.
Services can be defined by the application or within a module. Services are
often registered with the dependency injection container so that they can be
located or constructed as required and used by other components that
depend on them.
Controllers. Controllers are classes that are used to coordinate the construction
and initialization of views that are to be displayed in a region within the
application's UI. Controllers encapsulate the presentation logic that
determines which views are to be displayed. The controller will use Prism's
view-switching navigation mechanism, which provides an extensible URIbased navigation mechanism to coordinate the construction and placement
of views within regions. The Application Controller pattern defines an
abstraction that maps to this responsibility.
Bootstrapper. The Bootstrapper component is used by the application to
initialize the various Prism components and services. It is used to initialize
the dependency injection container to register any application-level
components and services with it. It is also used to configure and initialize the
module catalog and the shell's view and view model or presenter.
Prism is designed so that you can use any of the preceding capabilities and design
patterns individually, or all together, depending on your requirements and your
application scenario. You can use the MVVM pattern, modularity, regions,
commands, or events in any combination without having to adopt all of them. Of
course, if you want to take full advantage of the benefits that separation of
concerns and loose coupling offers, you will typically use many of Prism's
capabilities and design patterns in conjunction with each other. The following
illustration shows a typical Prism application architecture and shows how all the
various capabilities of Prism can work together within a multi-module composite
application.
Using Prism
Now that you've seen the major capabilities and design patterns that Prism
supports, it's time to see how easily you can start to use Prism when developing a
new application. This section provides an overview of the first few steps required to
create a basic Prism application. You can extend this basic application to leverage
the additional capabilities and design patterns provided by Prism, as required by
your scenario.
Note: Although the Prism Library can be easily used to build new composite WPF
applications, you can also use Prism with existing applications that want to take
advantage of one or more Prism capabilities or design patterns.
A Prism application typically consists of a shell project and multiple module projects.
The following illustration shows common activities needed when developing a
composite application using the Prism Library.
sign the Prism Library assemblies with your own strong name or certificate as part
of your build process.
Define the Shell
The application shell provides the basic layout for the application. This layout is
defined using regions that modules can use to place views. Views, like shells, can
use regions to define discoverable areas that content can be added to, as shown in
the following illustration. Shells typically set the appearance for the entire
application and contain the styles that are used throughout the application.
Exploring Prism
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. The source code also includes
Prism.PubSubEvents and Prism.Mvvm assemblies.
Prism binary assemblies. Signed binary versions of the Prism Library
assemblies. These assemblies can be downloaded from NuGet by searching for
Prism, Prism.Composition, Prism.PubSubEvents, and Prism.Mvvm,
Prism.Interactivity, Prism.UnityExtensions, and Prism.MefExtensions. These NuGet
packages will load dependencies such as the Unity Application Block and the
Service Locator.
The Prism NuGet package will download the Prism.Composition,
Prism.PubSubEvents, Prism.Mvvm, Prism.Interactivity,
Prism.PubSubEvents, and Prism.Mvvm NuGet packages.
Code samples. Prism includes a reference implementation sample and QuickStart
samples. The Stock Trader Reference Implementation is a comprehensive sample
application that illustrates how Prism can be used to implement real-world
application scenarios. The reference implementation is intentionally incomplete,
but they illustrate how many of the patterns in Prism can work together within a
single application. The QuickStart samples include several small, focused sample
applications that illustrate the MVVM pattern, navigation, UI composition,
modularity, commanding, event aggregation, and interactivity.
Documentation. The Prism 5.0 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 an 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:
Initializing Applications. This topic discusses what needs to happen to get a
user or a user gesture needs to raise an event that invokes a command. In each of
these scenarios the view model should not need to know about the view. The first
scenario is handled by using InteractionRequests and
InteractionRequestTriggers. The second scenario is handled by
InvokeCommandAction.
MVVM QuickStart. This 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.
Commanding QuickStart. This QuickStart demonstrates how to build a WPF UI that
uses commands provided by the Prism.Mvvm Library to handle UI actions in a
decoupled way.
UI Composition QuickStart . This QuickStart demonstrates how to build WPF 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 WPF 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.
Event Aggregation QuickStart. This QuickStart demonstrates how to build a WPF
application that uses the Event Aggregator service. This service enables you to
establish loosely coupled communications between components in your
application.
More Information
Prism assumes you have hands-on experience with WPF. If you need general
information about WPF , see the following resources:
Community
Prism's community sites are:
Prism: http://www.codeplex.com/Prism
PubSubEvents (Event Aggregator): http://www.codeplex.com/pnpPubSub
MVVM (Model-View-ViewModel): http://www.codeplex.com/pnpMvvm
On this these community sites, you can post questions, provide feedback, or
connect with other users for sharing ideas. Community members can also help
Microsoft plan and test future offerings and download additional content, such as
extensions and training material.