Ian Smith from www.irascian.com gives the Silverlight UK User Group, his thoughts on PRISM and its usage with Silverlight.
This presentation was given on 29th September 2009 at the EMC Consulting offices in London.
1. Tips and tools for creating and presenting wide format
slides
WIDESCREEN
PRESENTATION
2. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
Agenda
PRISM and .NET RIA Services
PRISM
What is it?
Documentation and Installation
PRISM Patterns
Quickstarts
MVVM
MEF
Reducing the Cut and Paste Overhead
3. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
Up-Front Disclaimer
PRISM and .NET RIA Services
Stealing one person’s work is plagiarism
Stealing several people’s work is research ;-)
Note: Most photos used in this presentation were purchased from IStockPhoto.com, who retain copyright.
4. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
If PRISM Were a Party
PRISM and .NET RIA Services
5. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
What is PRISM? – Microsoft P&P Definition
PRISM and .NET RIA Services
Composite Application Library source code
Unity Extensions for Composite Application
Library
source code and binaries
A Reference Implementation (Stock Trader)
PRISM QuickStarts
Documentation (chm and PDF formats)
Ref: http://www.microsoft.com/prism
6. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
What is PRISM? – (Better) Sparkling Client Definition
PRISM and .NET RIA Services
A collection of libraries (a smorgasboard or
buffet
of options) for implementing best practices in
Silverlight and WPF
It supports modularity, master pages
(regions),
loosely-coupled communication (eventing),
commanding (MVVM help!) and multi-
targetting
(WPF and Silverlight code sharing).
Most Silverlight/WPF apps can benefit from
PRISM
Ref: http://www.sparklingclient.com/prism-
silverlight/
7. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
PRISM - Portable, Reusable, Integrated Software Modules
PRISM and .NET RIA Services
Ref: Thanks to @pauliom for coming up with a PRISM acronym!
Dynamic/on-demand load of XAP files
Remove component dependencies
Make code more maintainable
Make code more testable
Ease team development
Provide Commanding support for MVVM
Provide reuse of code across applications
Maintain separation of roles
Reduce contention between multiple
developers
Reduce initial XAP file download size
Share code between WPF and Silverlight
8. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
PRISM – Why Should I Care What The Old Fart Presenter Says?
PRISM and .NET RIA Services
“We’re trying to take some of those
PRISM concepts and bake them
directly into Silverlight and
WPF… You’re going to see much
more native support for MVVM. A
lot of things in PRISM today you’ll
see the same or some flavour of it
in the core that make the PRISM
concepts easier to apply.”
Scott Guthrie
Corporate VP .NET Developer Division
Online Q&A, 28th May 2009
“If you want guidance, than I say
that something like PRISM is good
for you in almost any business
application”
“I see a lot of applications go
wrong. They tend to go wrong in
the same way over and over again.
The concepts that PRISM fosters
help you find a way out of those
familiar mistakes.”
Ward Bell
DevForce Product Manager, IdeaBlade
http://neverindoubtnet.blogspot.com/2009/05/are-we-overselling-
prism.html
9. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
PRISM Guidance Documentation
PRISM and .NET RIA Services
Ref:
http://compositewpf.codeplex.com/
Release/ProjectReleases.aspx?
ReleaseId=14982
Get the PDF
Version here
10. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
PRISM – Why so much documentation?
PRISM and .NET RIA Services
Ref: PRISM Guidance Documentation
(Page 9 of PDF version)
Guidance for WPF and
Silverlight
Design Concepts
Container Modularity
UI
Composition
Multi-
Targetting
Patterns
Patterns Overview
Library and Baseline
Architecture
Technical Concepts and How-
TosBootstrappe
r
Comman
ds
Communicati
on
Container and Services Deployment
Event
Aggregation
Modul
e
Region
Shell and
View
UI
Composition
Multi-
Targeting
Designer
GuidanceStock Trader Ref Impl
Reference
Implementation
QuickStarts and Hands-On Lab
Commandin
g
WPF
HOLSilverlight
HOL
Multi-
Targeting
Event
AggregationUI
Comp
11. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
PRISM Download and Installation
PRISM and .NET RIA Services
Ref: http://www.sparklingclient.com/downloading-and-building-
prism/
Only needed for
Multi-Targetting of
WPF and Silverlight
MSDN/Microsoft Download
CodePlex Documentation (“The Book”)
This is the one you
need for PRISM2
(PDF format)
PRISM (June 2008) =
WPF only
PRISM v2 (Feb 2009) =
WPF and Silverlight
12. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
PRISM Patterns
PRISM and .NET RIA Services
Composite User
Interface
Modularity Testability
Composite and Composite
View
Command
Adapter
Separated Interface and
Plug-in
Service Locator
Event Aggregator
Facade
Inversion of Control
Separated Presentation
(MVVM)
Host Application
Shell
Presenter
Modules
View
ViewMode
l
Model
Shell
Registry
Regio
n
Comman
d
Composite
View
Adapter
Separated
Presentation
Service/
Dependency
Injection
Container
Inversion of
Control
Service
Locator
Serparated Interface
Plug in
Loading Services
Event Aggregator
Core Services
Module Proferred
Services
13. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
Regions
PRISM and .NET RIA Services
The following controls can be exposed as
regions:
System.Windows.Controls.ContentContro
l
(and derived controls)
System.Windows.Controls.ItemsControl
(and derived controls)
Controls derived from
System.Windows.Controls.Primitives.Sele
ctor
(eg TabControl)
Name=“BannerRegion”
Name=“NewsRegion”
Name=“ContentRegio
n”
Name=
“NavigationRegion”
14. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
Demo – Regions “Hello World”
PRISM and .NET RIA Services
15. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
Services
PRISM and .NET RIA Services
Provide functionality to other
components in a loosely-
coupled
way through an interface.
Often a
singleton.
Any functionality that you
need
which provides an API surface
is a
service.
PRISM provides some
services
16. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
The Container
PRISM and .NET RIA Services
The place you go to ask for a service
(usually at an interface level)
Allows multiple modules to talk to each other
without
having a direct reference
Handles lifetime management
PRISM is not hung up about who the provider is
Unity Ninject
Castle
Windsor
17. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
Modules
PRISM and .NET RIA Services
Modules can be discovered and loaded at run tim
Modules are self-contained but can communicate
other modules and access services
Modules reduce the friction of maintaining, adding
and removing system functionality.
Define/
Discover
Modules
Load
Modules
Initialize
Modules
18. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
Modules – QuickStart Code Review
PRISM and .NET RIA Services
Bootstrapper
Unity
Bootstrapper
Module Manager
ModuleInf
o
ModuleInfoGrou
p
ModuleCatalog
IModuleTypeLoader
ModuleInitializer W X Y Z
Modules
19. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
Quick Starts
PRISM and .NET RIA Services
Modularity
Defining Modules in Code
Remote Modularity
View Discovery and Composition
View Discovery Composition
View Injection Composition
Commanding
Handling UI Interactions in a de-coupled way
Event Aggregation
Establish Loosel-coupled communications
between components
Multi-Targetting
Creating applications to multi-target desktop
WPF and Silverlight RIA
20. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
MVC vs MVP vs MVVM
PRISM and .NET RIA Services
MVC MVP MVVM
Ref: http://nirajrules.wordpress.com/2009/07/18/mvc-vs-mvp-vs-
mvvm/
21. MVVM
PRISM and .NET RIA Services
Ref: http://karlshifflett.wordpress.com/2008/11/08/learning-wpf-m-v-vm/
Unit
Testing
View XAML No (or very little) code behind
Data Template
Data binds to ViewModel
properties including UI
Commands
ViewModel
Command
Binding
Data
Binding
Change
Notification
Change
Notification
Data
Passthrough
Model
Exposes public properties. Abstracting Model
Exposes Commands as PRISM
DelegateCommand<T>
Business Layer performs Actions on Model eg
CRUD
INotifyPropertyChanged
Exposes public properties.
IDataErrorInfo
INotifyPropertyChanged
Business
Layer
Data Layer
22. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
Commanding
PRISM and .NET RIA Services
DelegateCommand<T>
23. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
Event Aggregation
PRISM and .NET RIA Services
CompositePresentationEve
ntCompositePresentationEve
nt
Event Aggregator
Publisher
Publisher Subscriber
Subscriber
Subscriber
24. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
MEF
PRISM and .NET RIA Services
Managed Extensability
Framework
v1.0 Intended for application extensibility after delive
.xap “load on demand” capability (PRISM overlap)
Under the hood “IoC on steroids” = just another PRIS
“provider”?
Ships with .NET 4.0/Visual Studio 2010
Available (on CodePlex) for Visual Studio 2008 SP1
Takes modularisation to the next level
Future version: XAML Markup extension for Silverligh
to allow properties to be wired up for contracts and o
first class support for declaring catalogues in XAML
25. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
Ongoing Constructive Debate
PRISM and .NET RIA Services
PRISM Event Aggregation
“The PRISM
implementation
is clunky and
awkward to use”
“I don’t like any
code behind in
the View”
“Yes. It smells
wrong. How
about this
instead ....?”
“Clever. But it
feels like a
HACK. Here’s
why it was done
that way...”
Code Behind in the View
Jeremy D
Miller
Ward Bell Glenn Block
“That can make
the code harder
to maintain”
Shawn
Wildermuth
Glenn Block
“Herding Code” podcasts #58 and #59
herdingcode.com
Presentation Patterns Parts 1 and 2
Jeremy Miller (“Presentation Patterns” author)
Ward Bell (DevForce)
Glenn Block (Microsoft P&P, MEF)
Rob Eisenberg (Caliburn)
26. Widescreen Advantages
PRISM Co-existence with Blend
PRISM and .NET RIA Services
Ref: http://johnpapa.net/silverlight/using-blend-with-prism-apps-in-silverlight-3/
Put all resources in resource dictionaries (in
infrastructure project)
Add an App.xaml file to each module (project)
Add link to the resource dictionary in each App.xaml
Modify csproj file to conditionally load App.xaml file for
Blend
27. Widescreen Advantages
PRISM – Removing the ‘Plumbing’ Overhead
PRISM and .NET RIA Services
Dave Hill’s PRISM Quick Start Kit (and update)
http://blogs.msdn.com/dphill/archive/2009/06/15/prism-quick-start-kit-update.aspx
Dave Kehring’s Snippet for PRISM
DelegateCommand
http://blog.whconsult.com/2009/02/01/CodeSnippetForPrismDelegateCommand.aspx
Andrea Boschin’s Snippet for Writing PRISM
Commands
http://www.silverlightplayground.org/post/2009/07/09/A-code-snippet-to-quickly-
write-Prism-commands.aspx
Ref: http://blogs.msdn.com/devkeydet/archive/2009/07/17/prism-visual-studio-templates-including-
mvvm.aspx
28. Widescreen Advantages
.NET RIA Services – Road Map
PRISM and .NET RIA Services
July 2009 – Updated ‘Preview’ Release
Lots of changes since MIX ‘Alpha Preview’ (Feb 2009) and May 2009 CTP
“At your own risk Go live” license
November 2009 (PDC) – Beta
Core feature work
Visual Studio 2010/.NET 4 support
Move to ADO.NET Data Services as underlying
protocol
2010 (MIX in February?) Release To Web
Alignment with other products
Ref:
http://silverlight.net/forums/p/101160/230835.aspx#230835
29. Widescreen Advantages
.NET RIA Services – N-Tier Design
PRISM and .NET RIA Services
Databas
e
Web
Service
View Data
Acces
s
Layer
(DAL)
Context
Object
Shared
Code
Code
Gen
Service
Metadata
Shared
Code
.NET RIA Services
Application Logic Application
Logic
30. Widescreen Advantages
Side by side material
fits more naturally.
Widescreen adds
drama to graphics and
images.
.NET RIA Services - Demo
PRISM and .NET RIA Services
Demonstration of
The RIA Link
Create a DomainService class
Build solution and examine Generated_Code folder
Add MetaData to the Entity
Sharing files between Client and Server
Warning: .NET RIA Services and Resharper do
not play well together because Resharper can’t
see the Generated Code and will throw errors.
31. Widescreen Advantages
Links
PRISM and .NET RIA Services
Sparkling Client podcasts
http://www.sparklingclient.com/
Shawn Wildermuth blog
http://wildermuth.com/
Ward Bell blog
http://neverindoubtnet.blogspot.c
om/
Glenn Block blog
http://blogs.msdn.com/gblock/
John Papa blog
http://johnpapa.net/
Brad Abrams blog
http://blogs.msdn.com/brada
Nikhil Khotari blog
http://www.nikhilk.net/
Downloading PRISM Guide
http://www.sparklingclient.com/downloadi
ng-and-building-prism/
Using PRISM and .NET RIA Services
Together
http://blogs.msdn.com/dphill/archive/2009
/08/17/prism-and-net-ria-services.aspx
Using Silverlight 3 Navigation with PRISM
http://www.codeproject.com/KB/silverlight
/sl3prismnav.aspx
32. Tips and tools for creating and presenting wide format
slides
WIDESCREEN
PRESENTATION
Questions?
Notes de l'éditeur
CAB was a “tightly coupled framework for building loosely coupled applications”. PRISM is something else. You’re not being asked to buy into an end-to-end story.
“It’s from the Microsoft Patterns and Practices Group – ‘Nuff said!”
Successor to the Composite Application Block (which “sucked”!)
“Microsoft P&P never tell you when using their code is NOT appropriate”
“I’m not building a dashboard – I don’t need it!”
“Installation/Documentation is a pig” (Does that make Silverlight/WPF the lipstick?)
CAB was a “tightly coupled framework for building loosely coupled applications”. PRISM is something else. You’re not being asked to buy into an end-to-end story.
“It’s from the Microsoft Patterns and Practices Group – ‘Nuff said!”
Successor to the Composite Application Block (which “sucked”!)
“Microsoft P&P never tell you when using their code is NOT appropriate”
“I’m not building a dashboard – I don’t need it!”
“Installation/Documentation is a pig” (Does that make Silverlight/WPF the lipstick?)
TODO: Show this pictorially!
Region is a mechanism that can be used to expose a particular visual way of displaying user controls (views). Regions can be accessed in a de-coupled way using their names
Regions support dynamic adding/removal of views at run time
The following controls can be exposed as regions:
System.Windows.Controls.ContentControl (and derived controls)
System.Windows.Controls.ItemsControl (and derived controls)
Controls derived from System.Windows.Controls.Primitives.Selector (eg TabControl)
Advantages:
Components don’t need to locate dependencies or manage their lifetimes
Allows swapping of implementations without affecting the component
- - > Eases Testability by allowing dependencies to be mocked
Increases maintainability by allowing new services to be easily added
Modules can be put into groups and annotated with which xap files they’re to be included with. PRISM modularity will deal with “when available/load across wire on demand” issues instead of developer having to worry about it.
Need to create a host for all your modules (“the Shell”). Do you want modules to be discovered or injected depends on whether you want to use regions or not. You can build a catalog of modules based on authorisation on the server and then only send code over the wire that applies.
Three-step process during application life-cycle
Module Catalog “discovers” modules. Contains collection of metadata about the modules which can then be consumed by the Module Manager Service
Module Manager Service co-ordinates module initialisation, managing retrieval, validation and subsequent initialisation
Instantiates each module’s Module Initialize class and invokes the Initialize method on each
Modules can be put into groups and annotated with which xap files they’re to be included with. PRISM modularity will deal with “when available/load across wire on demand” issues instead of developer having to worry about it.
Need to create a host for all your modules (“the Shell”). Do you want modules to be discovered or injected depends on whether you want to use regions or not. You can build a catalog of modules based on authorisation on the server and then only send code over the wire that applies.
Three-step process during application life-cycle
Module Catalog “discovers” modules. Contains collection of metadata about the modules which can then be consumed by the Module Manager Service
Module Manager Service co-ordinates module initialisation, managing retrieval, validation and subsequent initialisation
Instantiates each module’s Module Initialize class and invokes the Initialize method on each
Event Aggregation comes in when you have two views that want to speak. Remember The Shell should NOT be used as the communicator that gets bloated. Simple publish/subscribe model based on an event type. If I publish an event that nobody’s listening to or subscribe to an event that’s not published the overhead is low. It doesn’t care about the timing. It’s a one to many loosely coupled mechanism.
Dependency Injection allows you to say “I need something” and Container will know about what’s available.
Example: Region for list of speakers. Region for speaker details.
Region Manager is needed. Module gets instantiated through Dependency Injection and uses Constructor injection to pass in the Region Manager. You’d do same thing with IEventAggregator etc if you needed them. Works great for testing with Mock data injection.
MEF
Managed Extensibility Framework (general compositional technology to avoid manually creating objects through new()). To help developers write apps that can be extended by 3rd parties after the application has been deployed. Under the hood it's designed for general compositional needs. Extensible rules engine would be good scenario for customisation. Consistent API across different platforms (eg Office and Visual Studio). Separation of Concerns is big value item at low level if not public face. MEF allows you to harden meta information that can be examined before objects are created.
MEF and Silverlight
Specific Silverlight stuff (and solution file) added in Preview 6. CRM application that wants to allow 3rd party plug-ins to be plugged in. With MEF new stuff can be brought in which host has no knowledge of. For large scale LOB apps MEF gives ability to deploy in separate xap files which can then be imported on demand (overlaps with PRISM here). MEF takes modulariastion to the next level. Modules themselves can become monolithic but in MEF modules can have modules which can have modules. Working on a XAML integration piece. Today IOC container has issue because XAML is building up hierarchy. Allow UI elements to import into tree. Looking at markup extension for Silverlight to allow things that don't know anything about MEF to wire up properties for contracts. First class support for declaring catalogues in XAML.
Event Aggregation comes in when you have two views that want to speak. Remember The Shell should NOT be used as the communicator that gets bloated. Simple publish/subscribe model based on an event type. If I publish an event that nobody’s listening to or subscribe to an event that’s not published the overhead is low. It doesn’t care about the timing. It’s a one to many loosely coupled mechanism.
Dependency Injection allows you to say “I need something” and Container will know about what’s available.
Example: Region for list of speakers. Region for speaker details.
Region Manager is needed. Module gets instantiated through Dependency Injection and uses Constructor injection to pass in the Region Manager. You’d do same thing with IEventAggregator etc if you needed them. Works great for testing with Mock data injection.