0% found this document useful (0 votes)
95 views37 pages

Prism v2 - Intro To Composite Application Guidance and Library

This summary provides an overview of the key concepts presented in the Prism documentation: - Prism is a framework from Microsoft Patterns & Practices that helps build composite applications for WPF and Silverlight. It promotes separation of concerns and loose coupling through patterns like MVVM, modules, and events. - The core concepts of Prism include defining regions in the shell window for different views, developing features as independent modules, and communicating between modules using events. - The MVVM pattern supported by Prism separates application logic from user interface code to improve testability and code reuse. ViewModels act as the glue between views and models. - Prism helps manage complexity in large applications through

Uploaded by

mp.rathan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views37 pages

Prism v2 - Intro To Composite Application Guidance and Library

This summary provides an overview of the key concepts presented in the Prism documentation: - Prism is a framework from Microsoft Patterns & Practices that helps build composite applications for WPF and Silverlight. It promotes separation of concerns and loose coupling through patterns like MVVM, modules, and events. - The core concepts of Prism include defining regions in the shell window for different views, developing features as independent modules, and communicating between modules using events. - The MVVM pattern supported by Prism separates application logic from user interface code to improve testability and code reuse. ViewModels act as the glue between views and models. - Prism helps manage complexity in large applications through

Uploaded by

mp.rathan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 37

This deck (and sample code)

was used for several


presentations of this talk:
NH Code Camp (28-Feb-2009)
Beantown .NET User Group (05Mar-2009)
Boston Code Camp 11 (28-Mar2009)

Prism is 100% Resume


Compliant!
Fancy design patterns like
Model-View-ViewModel
Test-Driven Development
(TDD)
Loosely Coupled
Separation of Concerns
(SoC)
Interface-based
Programming
Dependency Injection (DI)
Inversion of Control (IoC)
Containers
Code-Behind minimalist

Modular, Composite
Application
Distributed Agile Team
Reverses baldness
Fluent Interfaces
Multi-Targeting
Silverlight and WPF
Routed Commands &
Routed Events
High Performance Dev
Increases your IQ 42
points
Data Binding
Architect (not Astronaut)

Introduction to Prism
Building Silverlight and WPF apps
with
Composite Applications Guidance
and
Composite Application Library
Bill Wilder

http://blog.codingoutloud.com

What is this talk about?


Targeting Silverlight and/or WPF
Managing complexity well
Best practices for Testability and design
patterns

Focus (mostly) around UI concerns


XAML, Code-behinds, Data Binding

Doing all of the above Using Prism


Runtime Library + Guidance + Project
Linker

Assumptions: You have


heard of
Windows Presentation Foundation
(WPF), Silverlight, XAML
Unit Testing (nUnit, ), TDD
Dependency Injection (DI), Inversion
of Control (IoC), Loose coupling
UI Design Patterns (MVC, MVP, )
Where are YOU coming from?

Goals of this Talk


Appreciate value of Prism for SL and WPF
Demonstrate a few key Prism concepts
Side effects:
A little WPF, Silverlight; discuss a couple
of Design Patterns / Anti-Patterns
Rules of engagement:
Ask questions any time

Terminology
Prism code name (which I will call it)
Prism v2 talking about 2nd release
Composite Application Guidance for
WPF and Silverlight official name
of whole package
Composite Application Library for
WPF and Silverlight runtime
support included sometimes called
CAL

Whats the problem?

f
f
US businesses annually spend ~tu
$250 billion on
software dev across approx 175,000
projects
s
Only 16 percent of these projects
s
finish on
i
schedule and within budget
h
t
y
Another 31 percent are cancelled,
mainly due
s
o
a
to quality problems
s
e
,
Another 53 percent
exceed
their budgets by an
t
y

average of 189
percent
a
n
i
k
Projects reaching a
completion deliver an average
O
of only 42 percent of the originally planned
features

[Credit: Jack Greenfield, Microsoft]

Industry
Response

Where did Prism come


from?
P&P =
Patterns & Practices Group
microsoft.com/patterns

Product Groups

Long cycle times


Strategic
Very large teams
Cost money
Fully Supported

Windows, Office, Exchange, Visual Studio, .NET,


Rapid cycle times
Sharepoint, Zune, ...
Small, focused agile
P&P Group
teams
Partner with community
EntLib, Unity, Arch Guide
CAB, Prism v1, Prism v2

Ship tactical solutions


now
Code and Guidance

Free, Open Source

Demo Stock Trader RI


(RI = Reference
Implementation)

Prism Key Concepts Eye


Chart

[Source CAL docs]

Shell, Regions, Views


Shell is main window for app
Shell defines (visual) Regions
Regions control where UI will appear
flexible
Views are displayed within Regions
WPF/Silverlight design, code, tooling
still applies Prism just makes it better

Views and Modules


Modules are DLLs (Projects)
Nice unit of work

You can decide when/whether to load


Modules can be configured to load code,
XML, or XAML
Modules can be downloaded (over http)
Can write your own loader rules

Modules have Views (usually)

Events
.NET events
Tight coupling (references in both directions)

WPF events
Looser coupling,
tree

(generally)

limited to same visual

Composite events
Looserer coupling; not limited to same visual
tree

More: Force to UI thread; event filtering


[Related to Commanding]

Prism Conventions+

Bootstrapper
Shell
One module per DLL
M-V-VM pattern

Dont need to follow the


conventions
But youll be glad you did

Prism is (relatively) Small

Silverlight

WPF

Prism

First Cut At
SaveAsPodcast App
Look at some code

Why Separate Concerns in


UI?

Optimizes Developer / Designer interaction


Dev in Visual Studio, Designer in Expression
Blend

Easier to Test
Now possible to Unit Test (vs. Integration Test)
Simpler problem isolation

Reuse opportunity goes way up


Same ViewModel can be reused with UI
variations

Better organized code is better code


Easier to understand, maintain
SE Principles: SoC, coupling, cohesion, SRP
(rendering, mouse & keyboard, disabled, hover)

How to Separate Concerns


in UI?

Use Code-Behinds reluctantly + M-V-VM


M-V-VM Model-View-ViewModel Pattern
Abbreviated as M-V-VM, MVVM
Often referred to simply as ViewModel
Specialization of Fowlers Presentation Model
pattern where View knows about ViewModel
http://martinfowler.com/eaaDev/PresentationModel.html

Prism docs refer to as Presentation Model


I will refer to as ViewModel pattern

ViewModel Pattern
Load external
data from
web services,
etc.
View

Data
Binding

ViewModel

Your Glue

Mode
l

Supported by WPF / SL

Powerful Data
Binding glue
provided free with
both Silverlight and

Custom code
(boring);
Automapper is
promising

Code-Behind Pattern (Old


Way)
Load external
data from
web services,
etc.
View

Your Other Glue

Mode
l

Code Behind for each


Control
Supported by WPF / SL

UI is the data
store for much of
the data (e.g.,
ListBox); logic

Custom code to
populate UI

Port SaveAsPodcast to
Prism
M-V-VM
Modules
Eventing
Event Filtering

Prism Rough Edges


You build it; P&P does not (yet) ship a
binary
No Prism-specific templates for Visual
Studio
Cannot unload a Module (MEF?)

When to go Composite?
(1/2)
You are designing complex WPF or
Silverlight applications, or
You are building an application that
presents information from multiple
sources through an integrated user
interface, or
You are developing, testing, and deploying
modules independently of other modules,
or
[Source CAL docs]

When to go Composite?
(2/2)
Your app will add more views and more
functionality over the coming years, or
You must be able to change the app
quickly and safely to meet emergent
business requirements, or
Your app is being developed by multiple
collaborating teams; or
Your app targets both WPF and
Silverlight, and you want to maximize
code sharing between platforms.
[Source CAL docs]

When to NOT go
Composite?
Your apps do not require any of the above
scenarios, or
Your application consists of a few simple
screens, or
You are building a prototype or demo, or
Your developers are not familiar with the
ideas and practices and do not have the
time to learn them. * COMPLEMENTARY
*
(remember the opening slide)

[Source CAL docs]

to
n
o
s
m
a
s
i
e
r Pr
g
e
n
s
o
r oo
W h
c

Why Prism
SoC + SRP + reducing plumbing code +
Unit Tests best way to handle
complexity and enable ability to
respond rapidly to requirement changes
M-V-VM best way to support the
previous item (in SL/WPF)
Prism best way to support the
previous item

Official Site
http://microsoft.com/composit
ewpf
-- or --

http://codeplex.com/composit
ewpf

Watch these spaces


Contrib site @
http://compositewpfcontrib.codeplex.com/
Assorted contributions for Prism (currently v1)

Channel 9 for tutorial videos


http://channel9.msdn.com/tags/Prism/

Infragistics control adapters for Prism @


http://ncal.codeplex.com/
Region Adaptors for Prism (currently v1)

Prism v2 References
http://www.microsoft.com/downloads/details.
aspx?FamilyID=fa07e1ce-ca3f-4b9b-a21b-e3fa1
0d013dd&DisplayLang=en
http://blogs.msdn.com/jmeier/archive/2009/02/1
8/new-release-composite-application-guidance-f
or-wpf-and-silverlight-v2-0-prism.aspx
http://timheuer.com/blog/archive/2009/02/18/pri
sm-2-released-composite-guidance-for-silverligh
t-lob.aspx
http://msdnrss.thecoderblogs.com/2009/02/18/co
mposite-application-guidance-for-wpf-and-silve
rlight-v20-prism/
http://tinyurl.com/d4s22b

Other Resources
Josh Smith on MVVM with WPF:
http://msdn.microsoft.com/en-us/magazine/dd4196
63.aspx
Brian Noyes on Understanding Routed Events and
Routed Commands in WPF:
http://msdn.microsoft.com/en-us/magazine/cc7854
80.aspx
WPF Commanding Overview:
http://msdn.microsoft.com/en-us/library/ms752308
.aspx
Martin Fowlers description of Presentation Model
pattern:
http://martinfowler.com/eaaDev/PresentationModel
.html
XAML Guidelines for Creating a Composite UI:
http://msdn.microsoft.com/enus/library/dd458877.aspx

Did I get to this?


What would happen if I ran the
Synchronous retrieval of the Podcast
feed from Silverlight?
Show the Prism docs

Silverlight for .NET


Challenge #1: not binary compatible with
runtimes that run on Windows desktop
But it is source compatible

Challenge #2: only a subset of runtime is


implemented on Silverlight

But most of the stuff that makes sense is there


(subset, security, useful, choose 1, async, cross-domain)

Challenge #3: XAML not same as WPF


But is converging on mostly a subset

Other miscellaneous differences


Suggestion: Write 1st in Silverlight, then
port to WPF

Question
s?

You might also like