This deck (and sample code) was used for several presentations of this talk: NH Code Camp...
-
Upload
alejandro-charles -
Category
Documents
-
view
214 -
download
0
Transcript of This deck (and sample code) was used for several presentations of this talk: NH Code Camp...
![Page 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/1.jpg)
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)
![Page 2: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/2.jpg)
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)
![Page 3: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/3.jpg)
Introduction to Prism
Bill Wilder
http://blog.codingoutloud.com
Building Silverlight and WPF apps withComposite Applications Guidance and
Composite Application Library
![Page 4: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/4.jpg)
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
![Page 5: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/5.jpg)
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?
![Page 6: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/6.jpg)
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
![Page 7: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/7.jpg)
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”
![Page 8: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/8.jpg)
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 th
is stuff
ain’t easy
![Page 9: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/9.jpg)
IndustryResponse
![Page 10: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/10.jpg)
Where did Prism come from?
P&P = Patterns & Practices Group
microsoft.com/patterns
![Page 11: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/11.jpg)
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, ...
![Page 12: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/12.jpg)
Demo Stock Trader RI
(RI = Reference Implementation)
![Page 13: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/13.jpg)
Prism Key Concepts Eye Chart
[Source CAL docs]
![Page 14: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/14.jpg)
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
![Page 15: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/15.jpg)
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)
![Page 16: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/16.jpg)
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]
![Page 17: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/17.jpg)
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
![Page 18: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/18.jpg)
Prism is (relatively) Small
WPF
Prism
Silverlight
![Page 19: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/19.jpg)
First Cut At “SaveAsPodcast” App
Look at some code…
![Page 20: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/20.jpg)
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)
![Page 21: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/21.jpg)
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– http://martinfowler.com/eaaDev/PresentationModel.html
• Prism docs refer to as Presentation Model• I will refer to as ViewModel pattern
![Page 22: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/22.jpg)
ViewModel Pattern
View Data Binding ViewModel ModelYour 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.
![Page 23: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/23.jpg)
Supported by WPF / SL
Code-Behind Pattern (Old Way)
View ModelYour 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.
![Page 24: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/24.jpg)
Port “SaveAsPodcast” to Prism
M-V-VMModulesEventing
Event Filtering
![Page 25: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/25.jpg)
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?)
![Page 26: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/26.jpg)
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]
![Page 27: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/27.jpg)
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]
![Page 28: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/28.jpg)
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]
![Page 29: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/29.jpg)
Wrong re
ason to
choose Prism
![Page 30: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/30.jpg)
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
![Page 31: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/31.jpg)
Official Site
http://microsoft.com/compositewpf -- or --
http://codeplex.com/compositewpf
![Page 32: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/32.jpg)
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)
![Page 33: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/33.jpg)
Prism v2 References• http://www.microsoft.com/downloads/details.aspx?Family
ID=fa07e1ce-ca3f-4b9b-a21b-e3fa10d013dd&DisplayLang=en
• http://blogs.msdn.com/jmeier/archive/2009/02/18/new-release-composite-application-guidance-for-wpf-and-silverlight-v2-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-v20-prism/
• http://tinyurl.com/d4s22b
![Page 34: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/34.jpg)
Other Resources• Josh Smith on MVVM with WPF:
http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
• Brian Noyes on Understanding Routed Events and Routed Commands in WPF: http://msdn.microsoft.com/en-us/magazine/cc785480.aspx
• WPF Commanding Overview: http://msdn.microsoft.com/en-us/library/ms752308.aspx
• Martin Fowler’s description of Presentation Model pattern: http://martinfowler.com/eaaDev/PresentationModel.html
• XAML Guidelines for Creating a Composite UI: http://msdn.microsoft.com/en-us/library/dd458877.aspx
![Page 35: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/35.jpg)
Did I get to this?
• What would happen if I ran the Synchronous retrieval of the Podcast feed from Silverlight?
• Show the Prism docs
![Page 36: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/36.jpg)
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, (subset,
security, useful, choose 1, async, cross-domain)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
![Page 37: 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.](https://reader036.fdocuments.net/reader036/viewer/2022062712/56649cae5503460f94971be7/html5/thumbnails/37.jpg)
Questions?