Prism is 100 Resume Compliant Trendy design patterns

  • Slides: 51
Download presentation
Prism is 100% Resume Compliant! • • • Trendy design patterns! Test-Driven Development Loosely

Prism is 100% Resume Compliant! • • • Trendy design patterns! Test-Driven Development Loosely Coupled Blend-able UIs Interface-based Programming Dependency Injection (DI) Io. C Containers Be a Code-Behind snob! Already know EF, MVC, WPF, (W)WF, WCF, and WTF? Add Prism to the list! Separate concerns with ease and style Write S. O. L. I. D. Code • Modular, Composite Apps! • Distributed Agile Teams • Twice as much code in double the time! • Fluent Interfaces • Multi-Targeting to Silverlight and WPF • Routed Commands & Routed Events • High Performance Dev • Increases your IQ 42 points • Data Binding • Architect (not Astronaut) • Best Practices galore!

Demystifying Prism Building Silverlight and WPF applications using Composite Applications Guidance (CAG) and Composite

Demystifying Prism Building Silverlight and WPF applications using Composite Applications Guidance (CAG) and Composite Application Library (CAL) New England Code Camp #13 27 -March-2010 Boston Azure User Group http: //bostonazure. org @bostonazure Boston West Toastmasters http: //bwtoastmasters. com Bill Wilder http: //blog. codingoutloud. com @codingoutloud Not here with my day job Only Bill’s personal views Copyright (c) 2010, Bill Wilder

How to Demystify Prism? • How did we get here? (motivation) • Demonstrate a

How to Demystify Prism? • How did we get here? (motivation) • Demonstrate a few key Prism concepts • Focus on Prism, not (for example): – XAML, Silverlight, WPF – M-V-VM Pattern • Making assumptions about your background – Unit Testing, DI, Io. C, So. C – Code-Behinds Ask questions any time image from http: //en. wikipedia. org/wiki/Rubik%27 s_cube

Photo from http: //en. wikipedia. org/wiki/File: Dispersion_prism. jpg Terminology • Prism code name (which

Photo from http: //en. wikipedia. org/wiki/File: Dispersion_prism. jpg Terminology • Prism code name (which I will call it) • Prism 2. 0 2 nd release (Feb 2009) • 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”

What’s the problem? • • • f f US businesses annually spend ~ $250

What’s the problem? • • • f f US businesses annually spend ~ $250 billion on u t software dev across approx 175, 000 projects s s finish on schedule Only 16 percent of these projects i h y and within budget t s Another 31 percent are cancelled, mainly due to o a quality problems , s e t y ’ Another 53 percent exceed their budgets by an a n i average of k 189 percent a O Projects reaching completion deliver an average of only 42 percent of the originally planned features [Credit: Jack Greenfield, Microsoft]

Industry Response

Industry Response

Where did Prism come from? P&P = Patterns & Practices Group microsoft. com/patterns

Where did Prism come from? P&P = Patterns & Practices Group microsoft. com/patterns

Product Groups • • • Long cycle times Strategic Very large teams Cost money

Product Groups • • • Long cycle times Strategic Very large teams Cost money Fully Supported Products: Windows, Office, Exchange, Visual Studio, . NET, Zune, . . . P&P Group • Rapid cycle times • Small, focused agile teams – Partner with community • Ship tactical solutions now Products: Ent. Lib, CAB, Unity, Prism v 1, Prism v 2, Arch Guide, … – Code and Guidance • Free, Open Source • More latitude, less legacy

Prism Key Concepts Eye Chart [Source CAL docs]

Prism Key Concepts Eye Chart [Source CAL docs]

 • Stock module • - send an Ticker. Symbol. Selected. Event to the

• Stock module • - send an Ticker. Symbol. Selected. Event to the Event. Aggregator • Other modules • - request to subscribe to Ticker. Symbol. Selected. Event

 • REPLAC NEXT SLIDE WITH VISUUALLS • Todo

• REPLAC NEXT SLIDE WITH VISUUALLS • Todo

Shell = Main Window

Shell = Main Window

Code Examine Demo Stock Trader RI (RI = Reference Implementation)

Code Examine Demo Stock Trader RI (RI = Reference Implementation)

What can Prism do for You? Manage complexity via loosely-coupled design & clean Separation

What can Prism do for You? Manage complexity via loosely-coupled design & clean Separation of Concerns at many levels • Composite UI (Regions) & Modules – Supports independent development and evolution • Loosely coupled Eventing and Commanding – Enhances support for M-V-VM Design Pattern • Design guidance and patterns that support both Unit Testing and Designer Integration • Excellent support for SL/WPF portability

 • <Text. Box Text="{Binding Path=Text. Contents}" Font. Size="36" /> • Classs Fred. View.

• <Text. Box Text="{Binding Path=Text. Contents}" Font. Size="36" /> • Classs Fred. View. Model • public string Text. Contents { get; set; }

The Case for Prism: “Silverlight++” • So. C + SRP + reducing plumbing code

The Case for Prism: “Silverlight++” • So. C + SRP + reducing plumbing code + Unit Tests best way to handle complexity and enable ability to respond rapidly to requirement changes • Composite Applications and M-V-VM best way to support the previous item (in SL/WPF) • Prism is an exemplar of modern-day best practices for the Silverlight and WPF platform • Prism sits atop full power of SL/WPF, and fully leverages Unity and. NET, enables Agile

Shell, Regions, Views • • Shell is main window for app Shell defines (visual)

Shell, Regions, Views • • Shell is main window for app Shell defines (visual) 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 live in Modules • Modules are DLLs (Visual Studio Projects) – Nice unit

Views live in Modules • Modules are DLLs (Visual Studio Projects) – Nice unit of work for a sub-team, testable • Shell decides when/whether to load Modules – Configured via code, XML file (WPF only), or XAML • Modules can be downloaded (over http) – Silverlight, WPF Click-Once can streamline startup – Can write your own loader rules • For its UI, a (Prism) Module loads its (Prism) View

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

Events • . NET events – Tight coupling (references in both directions) • WPF events – Looser coupling, (generally) limited to same visual tree • Composite events (Prism) – Looserer coupling; not limited to same visual tree – Subscriber and Publisher lifetimes not bound • More: Force to UI thread; event filtering

Prism “Conventions+” • • Bootstrapper Shell One module per DLL M-V-VM pattern (MVP good

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

Prism is (relatively) Small WPF Silverlight Prism

Prism is (relatively) Small WPF Silverlight Prism

Code Examine and Extend Hello World

Code Examine and Extend Hello World

How to Separate Concerns in UI? • • • Use Code-Behinds reluctantly + M-V-VM

How to Separate Concerns in UI? • • • Use Code-Behinds reluctantly + M-V-VM Model-View. Model Pattern Abbreviated as M-V-VM, MVVM Often referred to simply as View. Model Specialization of Fowler’s Presentation Model pattern where View knows about View. Model – http: //martinfowler. com/eaa. Dev/Presentation. Model. html • Prism docs refer to as Presentation Model • I will refer to as View. Model pattern

Code-Behind Pattern (Old Way) Load external data from web services, etc. View Your Other

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

View. Model Pattern (New Way) Load external data from web services, etc. (“usual stuff”)

View. Model Pattern (New Way) Load external data from web services, etc. (“usual stuff”) View Data Binding View. Model Your Glue Model Supported by WPF / SL Powerful Data Binding glue Custom code (boring); provided free with both Automapper is promising Silverlight and WPF

Code Modify Prism app UI to use M-V-VM

Code Modify Prism app UI to use M-V-VM

Prism Rough Edges • Coming in fall: Prism 4 – MEF alignment – Prism

Prism Rough Edges • Coming in fall: Prism 4 – MEF alignment – Prism templates, tooling – We do have Project Linker, David Hill’s templates • You build it; P&P does not ship a binary – Hopeful for Prism 4 – – http: //blogs. msdn. com/blaine/archive/2010/01/15/prism-4 -0. aspx http: //blogs. msdn. com/blaine/archive/2010/03/17/prism-4 -0 -plans. aspx • Cannot unload a Module from memory

When should you use Prism? ? ? ? ?

When should you use Prism? ? ? ? ?

to n o s m a s i e r Pr g e n

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

When to go Composite? (1/2) • You are designing “complex” WPF or Silverlight applications,

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

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

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]

Prism is not all-or-nothing • Can use Eventing, Commanding support without Composite Applications –

Prism is not all-or-nothing • Can use Eventing, Commanding support without Composite Applications – Better M-V-VM than possible with SL or WPF alone • Prism’s Project Linker tool eases sharing code across Silverlight and WPF • Prism’s design goals aligned with features in Silverlight and WPF – Expand your thinking beyond Win. Forms, Web. Forms • Read the docs and guidance!

Official Site http: //microsoft. com/compositewpf -- or -- http: //codeplex. com/compositewpf

Official Site http: //microsoft. com/compositewpf -- or -- http: //codeplex. com/compositewpf

Futures • http: //blogs. msdn. com/blaine/archive/2010/0 3/17/prism-4 -0 -plans. aspx

Futures • http: //blogs. msdn. com/blaine/archive/2010/0 3/17/prism-4 -0 -plans. aspx

Watch these spaces • “Contrib” site @ http: //compositewpfcontrib. codeplex. com/ – Assorted contributions

Watch these spaces • “Contrib” site @ http: //compositewpfcontrib. codeplex. com/ – Assorted contributions for Prism (currently v 1) • Channel 9 for tutorial videos – http: //channel 9. msdn. com/tags/Prism/ • Infragistics control adapters for Prism @ http: //ncal. codeplex. com/ – Region Adaptors for Prism (currently v 1)

Prism v 2 References • http: //www. microsoft. com/downloads/details. aspx? Family ID=fa 07 e

Prism v 2 References • http: //www. microsoft. com/downloads/details. aspx? Family ID=fa 07 e 1 ce-ca 3 f-4 b 9 b-a 21 be 3 fa 10 d 013 dd&Display. Lang=en • http: //blogs. msdn. com/jmeier/archive/2009/02/18/newrelease-composite-application-guidance-for-wpf-andsilverlight-v 2 -0 -prism. aspx • http: //timheuer. com/blog/archive/2009/02/18/prism-2 released-composite-guidance-for-silverlight-lob. aspx • http: //msdnrss. thecoderblogs. com/2009/02/18/composite -application-guidance-for-wpf-and-silverlight-v 20 -prism/ • http: //tinyurl. com/d 4 s 22 b

Other Resources • Josh Smith on MVVM with WPF: http: //msdn. microsoft. com/enus/magazine/dd 419663.

Other Resources • Josh Smith on MVVM with WPF: http: //msdn. microsoft. com/enus/magazine/dd 419663. aspx • Brian Noyes on Understanding Routed Events and Routed Commands in WPF: http: //msdn. microsoft. com/enus/magazine/cc 785480. aspx • WPF Commanding Overview: http: //msdn. microsoft. com/en-us/library/ms 752308. aspx • Martin Fowler’s description of Presentation Model pattern: http: //martinfowler. com/eaa. Dev/Presentation. Model. html • XAML Guidelines for Creating a Composite UI: http: //msdn. microsoft. com/en-us/library/dd 458877. aspx

 • David Hill’s Quick. Start Kit (new, raw): http: //blogs. msdn. com/dphill/archive/2009/0 5/29/prism-quick-start-kit.

• David Hill’s Quick. Start Kit (new, raw): http: //blogs. msdn. com/dphill/archive/2009/0 5/29/prism-quick-start-kit. aspx • David Hill’s updated Quick. Start Kik (I have not had chance to look at it – was just posted): http: //blogs. msdn. com/dphill/archive/2009/0 6/15/prism-quick-start-kit-update. aspx

Silverlight FCL/XAML != WPF FCL/XAML • http: //wpfslguidance. codeplex. com/Release/P roject. Releases. aspx? Release.

Silverlight FCL/XAML != WPF FCL/XAML • http: //wpfslguidance. codeplex. com/Release/P roject. Releases. aspx? Release. Id=28278

Did I get to this? • What would happen if I ran the Synchronous

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 desktop – But it

Silverlight for. NET • Challenge #1: not binary compatible with desktop – But it is source compatible (but see #2) • Challenge #2: runtime subset on Silverlight – But most of the stuff that “makes sense” is there (subset, security, useful, choose 1, async, cross-domain) • Challenge #3: Silverlight XAML != WPF XAML – But is converging on mostly a subset • Other miscellaneous differences… – http: //wpfslguidance. codeplex. com/Release/Project. Releases. aspx? Release. Id=28278 • Suggestion: Write 1 st in Silverlight, then port to WPF

Questions?

Questions?

Name some major Prism concepts • • Bootstrapper (a convention) Shell (“main window”) Region

Name some major Prism concepts • • Bootstrapper (a convention) Shell (“main window”) Region View Module Service (talk to outside world, web service) Event (loosely coupled, cross module) Command

How does the View get created? public partial class Bootstrapper : Unity. Bootstrapper {

How does the View get created? public partial class Bootstrapper : Unity. Bootstrapper { … protected override Dependency. Object Create. Shell() { // Container. Resolve is part of Unity Shell. View view = Container. Resolve<Shell. View>(); Application. Current. Root. Visual = view; return view; } …

How does View get its View. Model? • Bootstrapper. cs: Foo. View view =

How does View get its View. Model? • Bootstrapper. cs: Foo. View view = Container. Resolve<Foo. View>(); • Foo. View. cs: public Shell. View(Foo. View. Model view. Model) {…} • Foo. Module. cs (in IModule: Initialize): container. Register. Type<IFoo. View. Model, Foo. Service>();

View, View. Model, or Model? public class Foo : INotify. Property. Changed { //

View, View. Model, or Model? public class Foo : INotify. Property. Changed { // My most likely role is…? }

Transparent Platform Extensions vs. Prism Remote Module Loading Transparent Platform Extensions • New in

Transparent Platform Extensions vs. Prism Remote Module Loading Transparent Platform Extensions • New in Silverlight 3 • Supports caching of new platform features (browser does the caching) • DLR, Language Extension, Controls • Do not need to live in XAP • Specified in App. Manifest. xaml • Only can be downloaded from microsoft. com Prism Remote Module Loading • Modules for your application, not Platform • Defer loading for UX reasons, future modularity flexibility

What is a “View” • Prism uses the term to mean a visual area,

What is a “View” • Prism uses the term to mean a visual area, hosted in a module, that is displayed within a (Prism-defined) Region • M-V-VM uses the term to mean the implementation of your UI dealing with drawing the screen (but does not include logic) • Don’t confuse the two

What is a “Service” • Prism uses the term to refer to modules which

What is a “Service” • Prism uses the term to refer to modules which supply data and logical processing to Views in a loosely coupled manner • The SOA world uses the term to refer to (usually) application-independent business components which can be invoked over a network using a standard protocol, usually SOAP or REST-based; often implemented as “Web services” using ASMX or WCF in. NET

Next Steps • Download Prism • Look at the samples, read the docs •

Next Steps • Download Prism • Look at the samples, read the docs • Download David Hill’s updated Quick. Start Kit from http: //blogs. msdn. com/dphill/archive/2009/0 6/15/prism-quick-start-kit-update. aspx