28
Shine a Light with Shine a Light with “Prism” “Prism” Dave Bost Dave Bost Developer Evangelist http://davebost.com/blog e-requisites for this presentation: ) IoC, DI ) Presentation patterns vel: Intermediate

Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

Embed Size (px)

DESCRIPTION

This is the slide deck of the session I presented at VSLive San Francisco 2009 on Feb. 26, 2009

Citation preview

Page 1: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

Shine a Light withShine a Light with“Prism”“Prism”Dave BostDave BostDeveloper Evangelisthttp://davebost.com/blog

Pre-requisites for this presentation:

1) IoC, DI 2) Presentation patterns

Level: Intermediate

Page 2: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

http://thirstydeveloper.comhttp://thirstydeveloper.com

“Looking at someone’s code, but with audio”

Page 3: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

Session Objectives And Session Objectives And TakeawaysTakeaways Session Objective(s):

– Able to determine RIA composite application scenarios and recommend solutions for the scenarios using Prism for Silverlight and WPF.

Prism – V2 in Feb shipped Feb. ‘09 (Silverlight) Provides written and code-example guidance

for composite solution space Supports targeting both Silverlight & WPF

composite applications

Page 4: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

Are you building this?Are you building this?

Page 5: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

Or something like this?Or something like this?

Page 6: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

The ChallengeThe Challenge

Page 7: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

The SolutionThe Solution

Page 8: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

Consider PrismConsider Prism

Provides Tools to help with separating your app and composing at run-time:

• Tools to help you discover the pieces• Strategies and guidance for recomposition• Approaches for communication between these separate components• Event help with targeting both Silverlight and WPF

Provides Tools to help with separating your app and composing at run-time:

• Tools to help you discover the pieces• Strategies and guidance for recomposition• Approaches for communication between these separate components• Event help with targeting both Silverlight and WPF

Page 9: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

Prism-What’s in the boxPrism-What’s in the box

Prism – Composite Client Application Guidance for WPF and Silverlight– Library– Reference Implementation– Documentation– Quick-Starts & How-To’s– Community – CodePlex

Prism 1.0 – WPF– Released July 2008

Prism 2.0 – Silverlight– Released February 2009

Page 10: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

Reference ImplementationReference Implementation

Page 11: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

Prism Core ConceptsPrism Core Concepts

Page 12: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

ModulesModules

Unit Of Application Assembly– Collection of Related Components

– Feature, Services, Views, Data Access

– Mandatory or Optional or Role Specific

– Example: Banking app: Checking Module, Credit Card Module, Trading Module, News Module

Unit Of Development– Independent Development

– Independent Testing

Unit Of Deployment– Up-Front, Background or On-Demand

Page 13: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

ModulesModules Module Discovery

– Pluggable Catalogs

Module Loading– Background or On-Demand

Module Module LoaderLoaderModule Module LoaderLoader

Extended InExtended InPrism 2.0!Prism 2.0!

Page 14: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

DemoDemo

Modules & Catalogs

Page 15: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

UI CompositionUI Composition Shell – Application Host Window Regions – Named Areas For View Placement Views – Encapsulate UI & Presentation Logic

RegionRegion

RegionRegion

RegionRegion

// View InjectionIPositionPresentationModel presentationModel = …;

IRegion mainRegion = regionManager.Regions[ "MainRegion" ];

mainRegion.Add( presentationModel.View );

<TabControl RegionManager.RegionName= "MainRegion">

<ItemsControl RegionManager.RegionName= “ResearchRegion” />

<ContentControlRegionManager.RegionName= “ActionRegion” />

Page 16: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

UI CompositionUI Composition View Discovery Composition:

– Less Complex– Black Box ‘App Assembly’ Composition– Select Views & Pull into Region

New InNew InPrism 2.0!

Prism 2.0!

RegionRegion

RegionRegion

RegionRegion

<TabControl RegionManager.RegionName= "MainRegion">

regionManager. RegisterViewWithRegion( "MainRegion", typeof( MainView ) );

Page 17: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

DemoDemo

UI Composition

Page 18: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

Commands and EventsCommands and Events

Delegate & Composite Commands– Simplified Command Handling

Event Aggregator– Loosely Coupled Pub/Sub Events

Module BModule B

CustomerPresenterCustomerPresenter

Module AModule A

OrderPresenter

OrderPresenter

EventAggregator

EventAggregator

Subscribe

Publish

Event

Page 19: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

Prism Silverlight Logical Prism Silverlight Logical ArchitectureArchitecture

HOST APPLICATIONHOST APPLICATION LOADING SERVICESLOADING SERVICES

CORE SERVICESCORE SERVICES

MODULE PROFFERED SERVICES

MODULE PROFFERED SERVICES

ModulesModulesMODULESMODULES

PresenterPresenter

ModelModel

ViewView

ModelModel

ModuleCatalog

Module Loader

EventAggregator

Logging

RegionManager

Un

ity

Module Initializer

Page 20: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

Multi-TargetingMulti-Targeting User Experiences

– Desktop – In the Office, Full Functionality, Offline – RIA – Out of the Office, Functional Subset, Online

WPFApplication

WPFApplication

Silverlight (RIA)Application

Silverlight (RIA)Application

CLR - SilverlightCLR - SilverlightCLR - SilverlightCLR - Silverlight CLR DesktopCLR DesktopCLR DesktopCLR Desktop

BCLBCLBCLBCL BCLBCLBCLBCL

BROWSER DESKTOP

Page 21: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

Multi-Targeting: StrategiesMulti-Targeting: Strategies

Start with LCD Use Links and Parallel Project Structures Separated Presentation Strategies Keep single source If not, apply the sieve

#IF SILVERLIGHT#IF SILVERLIGHT

Partial ClassesPartial Classes

Partial MethodsPartial Methods

Separate ClassesSeparate Classes

Rewrite the CodeRewrite the Code

Page 22: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

WP

FW

PF

CLR - SilverlightCLR - SilverlightCLR - SilverlightCLR - Silverlight CLR DesktopCLR DesktopCLR DesktopCLR Desktop

BCLBCLBCLBCL BCLBCLBCLBCL

BROWSER DESKTOP

Multi-TargetingMulti-Targeting

ControllersControllers

ModelsModels

PresentersPresenters

ViewsViews

ModelsModels

ControllersControllers

PresentersPresenters

ViewsViews

Page 23: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

DemoDemo

Multi-Targeting

Page 24: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

Where Can You Find It?Where Can You Find It?

www.microsoft.com/compositewpf www.codeplex.com/compositewpf http://msdn.microsoft.com/practices http://blogs.msdn.com/bobbrum http://blogs.msdn.com/blaine

Page 25: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

SummarySummary

Prism– Library of Patterns for Composite Client Applications– Targets WPF Desktop and Silverlight RIA Applications– View Disovery Composition, Separated Presentation

Patterns, Module Catalog– Multi-Targeting to reuse code between Silverlight and

WPF

Download from CodePlex and send us feedback

Page 26: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)

Dave Bost

thank you!

http://davebost.comhttp://twitter.com/davebost

Q&A

Page 27: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)
Page 28: Shine a Light with Prism (the Composite Application Guidance for WPF and Silverlight)