Presentation is loading. Please wait.

Presentation is loading. Please wait.

This deck (and sample code) was used for several presentations of this talk: NH Code Camp (28-Feb-2009) Beantown.NET User Group (05-Mar-2009) Boston Code.

Similar presentations

Presentation on theme: "This deck (and sample code) was used for several presentations of this talk: NH Code Camp (28-Feb-2009) Beantown.NET User Group (05-Mar-2009) Boston Code."— Presentation transcript:

1 This deck (and sample code) was used for several presentations of this talk: NH Code Camp (28-Feb-2009) Beantown.NET User Group (05-Mar-2009) Boston Code Camp 11 (28-Mar-2009)

2 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)

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

4 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

5 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?

6 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

7 Terminology Prism  code name (which I will call it) Prism v2  talking about 2 nd 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”

8 What’s the problem? US businesses annually spend ~ $250 billion on software dev across approx 175,000 projects Only 16 percent of these projects finish on schedule and within budget Another 31 percent are cancelled, mainly due to quality problems Another 53 percent exceed their budgets by an average of 189 percent Projects reaching completion deliver an average of only 42 percent of the originally planned features [Credit: Jack Greenfield, Microsoft] Okay, so this stuff ain’t easy

9 Industry Response

10 Where did Prism come from? P&P = Patterns & Practices Group

11 Product Groups Long cycle times Strategic Very large teams Cost money Fully Supported Rapid cycle times Small, focused agile teams – Partner with community Ship tactical solutions now – Code and Guidance Free, Open Source More latitude, less legacy P&P Group EntLib, Unity, Arch Guide CAB, Prism v1, Prism v2 Windows, Office, Exchange, Visual Studio,.NET, Sharepoint, Zune,...

12 Demo Stock Trader RI (RI = Reference Implementation)

13 Prism Key Concepts Eye Chart [Source CAL docs]

14 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

15 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)

16 Events.NET events – Tight coupling (references in both directions) WPF events – Looser coupling, (generally) limited to same visual tree Composite events – Looserer coupling; not limited to same visual tree More: Force to UI thread; event filtering [Related to Commanding]

17 Prism “Conventions+” Bootstrapper Shell One module per DLL M-V-VM pattern Don’t need to follow the conventions… But you’ll be glad you did

18 Prism is (relatively) Small WPF Prism Silverlight

19 First Cut At “SaveAsPodcast” App Look at some code…

20 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)

21 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 Fowler’s Presentation Model pattern where View knows about ViewModel – Prism docs refer to as Presentation Model I will refer to as ViewModel pattern

22 ViewModel Pattern View Data Binding ViewModelModel Your Glue Supported by WPF / SL Powerful Data Binding glue provided free with both Silverlight and WPF Custom code (boring); Automapper is promising Load external data from web services, etc.

23 Supported by WPF / SL Code-Behind Pattern (Old Way) View Model Your Other Glue UI “is” the data store for much of the data (e.g., ListBox); logic intertwined Custom code to populate UI Code Behind for each Control Load external data from web services, etc.

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

25 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?)

26 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]

27 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]

28 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]

29 Wrong reason to choose Prism

30 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

31 Official Site -- or --

32 Watch these spaces “Contrib” site @ – Assorted contributions for Prism (currently v1) Channel 9 for tutorial videos – Infragistics control adapters for Prism @ – Region Adaptors for Prism (currently v1)

33 Prism v2 References D=fa07e1ce-ca3f-4b9b-a21b- e3fa10d013dd&DisplayLang=en D=fa07e1ce-ca3f-4b9b-a21b- e3fa10d013dd&DisplayLang=en release-composite-application-guidance-for-wpf-and- silverlight-v2-0-prism.aspx release-composite-application-guidance-for-wpf-and- silverlight-v2-0-prism.aspx released-composite-guidance-for-silverlight-lob.aspx released-composite-guidance-for-silverlight-lob.aspx application-guidance-for-wpf-and-silverlight-v20-prism/ application-guidance-for-wpf-and-silverlight-v20-prism/

34 Other Resources Josh Smith on MVVM with WPF: us/magazine/dd419663.aspx us/magazine/dd419663.aspx Brian Noyes on Understanding Routed Events and Routed Commands in WPF: us/magazine/cc785480.aspx us/magazine/cc785480.aspx WPF Commanding Overview: Martin Fowler’s description of Presentation Model pattern: XAML Guidelines for Creating a Composite UI:

35 Did I get to this? What would happen if I ran the Synchronous retrieval of the Podcast feed from Silverlight? Show the Prism docs

36 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 (subset, security, useful, choose 1, async, cross-domain) – 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 1 st in Silverlight, then port to WPF

37 Questions?

38 Loose Coupling – How To Architect for general flexibility using Dependency Inversion & code to interfaces Use an IoC container (Unity, Structure Map, Castle Windsor) Unit test using IoC

Download ppt "This deck (and sample code) was used for several presentations of this talk: NH Code Camp (28-Feb-2009) Beantown.NET User Group (05-Mar-2009) Boston Code."

Similar presentations

Ads by Google