Beruflich Dokumente
Kultur Dokumente
www.wintellect.com
What we do
Consulting | Debugging | Training
Who we are
Founded by top experts on Microsoft Jeffrey Richter, Jeff Prosise and John Robbins our mission is to help our customers achieve their goals through advanced software-based consulting and training solutions.
How we do it
Consulting & Debugging
Architecture, analysis, and design services Full Lifecycle custom software development Content creation Project management Debugging & performance tuning
Training
On-site instructor-led training Virtual instructor-led training Devscovery conferences August 18-20, 2009
Agenda
Composite Applications Introduce Prism Prerequisites Dependency Injection Container (Unity) Shell and Regions Bootstrapper Modules Views
- View Discovery - View Injection
Composite Applications
- loosely-coupled modules - common shell - common services - separated presentation patterns - mockability/testability
What is Prism?
Formal name is Composite Application Guidance A set of guidance (not a framework) to build flexible composite client applications Whats included: - Composite Application Library reusable library code - Documentation, Quick Starts, Hands-On Labs - Reference Implementation (StockTraderRI) Key Benefits - Dependency Injection Container (via Unity Application Block) - UI Composition - Modularity - Multi-Targeting (Silverlight and WPF)
Prism Assemblies
Microsoft.Practices.Composite
- Core components such as Modularity, Logging Services - Nothing UI-specific
Microsoft.Practices.Composite.Presentation
- Commands, Regions, Events
Microsoft.Practices.Unity Microsoft.Practices.ObjectBuilder2
- Unity Container Application Block
Microsoft.Practices.Composite.UnityExtensions
- Base and Utility classes for use with Unity - UnityBootstrapper
Microsoft.Practices.ServiceLocation
- Common Service Locator interface
Prerequisite Concepts
Databinding
- UI elements bound to data in WPF/Silverlight
Resources
- Styles, brushes, data templates, etc
Routed Commands
- Actions independent of their UI exposure
Routed Events
- Events can be handled by multiple listeners up and down the visual tree
Dependency Properties
- Dependent on multiple providers (animation, parent, etc) - Built-in change notification
XAML
- Declarative language for initialization of objects and layout
Dependencies get automatically injected into component (Module) via Constructor or Setter injection
Allows registration of Types, Instances, Services with the Container
container.RegisterType<ILogger, MyLogger>();
Regions
Regions contain Views Regions can be ContentControl, ItemsControl, TabControl RegionAdapters allow you to create your own type of Regions Regions indicated by RegionName attached property
<ContentControl regions:RegionManager.RegionName="SelectionRegion />
Demo
Shell and Regions
Modules
Module represents a set of related concerns
- Contains Views, ViewModels, Presenters, Services, etc.
Designed to be discovered and loaded at run-time - ModuleCatalog can be loaded programmatically, from a config file,
from a directory (WPF), from a XAP file (SL), etc.
Communicates with other Modules and with the Shell in a loosely-coupled manner
Bootstrapper
UnityBootstrapper default bootstrapper base class
- Handles initialization with Unity - Can be replaced with non-Unity bootstrapper
Demo
Modules and Bootstrapper
Views
Main unit of UI construction in Composite Applications
- Usually a UserControl but could be a DataTemplate
Generally implemented using a Separated Presentation pattern such as Presentation Model, MVVM, MVP
View Injection - Created and displayed programmatically View Discovery - Created and displayed automatically
View Injection
Views added/removed from Regions directly by the Module
View Discovery
Views are registered by the Module and then automatically created and loaded View Discovery is simpler and preferred over View Injection
Demo
Adding a View
Model-View-ViewModel
- specialized version of Presentation Model Pattern - works well with Silverlight & WPF due to their databinding capabilities - ViewModel exposes the data and actions needed by the View - ViewModel sits below the UI layer - Views bind their DataContext to the ViewModel - Views tend to have very little code in code-behind files
Demo
Adding the ViewModel
Services
Services not always web services
Modules can contain application-specific services Modules register Services with the Container Some Services may be common across Modules
- Often in an Infrastructure or Common module
Demo
Adding a Service
Commanding
Provide a way to bind the UI to the action WPF Routed Commands flow up/down the visual tree Silverlight contains ICommand but has no implementation
Demo
Adding a Command
Eventing
Allows decoupling of publishers and subscribers EventAggregator is a container for events EventAggregator is created/injected upon first use by Prism
Event Aggregation
Demo
Adding an Event
Multi-Targeting
Silverlight and WPF are not binary-compatible Prism provides Project Linker Project Linker automatically syncs shared code and compiles for specific environment Non-UI code and components are easiest to share Separated Presentation Patterns are essential for multi-targeting Generally best to start with Silverlight since it is a subset Use #if SILVERLIGHT to force conditional compile
Resources
Composite Application Guidance (Prism) on CodePlex Unity on CodePlex Unity - Dependency Injection and Inversion of Control Container UI Composition Patterns The Dependency Injection Pattern What is it and why do I care? Prism for Silverlight - An Intro to Composite Applications (Video) How Commanding Works in Prism and MVVM (Video) Creating a modular application using Prism V2 Channel 9 videos Designing Composite Applications (Presentation slides) Using WCF + Silverlight 2 + PRISM : Gotchas Josh Smith on MVVM in WPF Brian Noyes on Understanding Routed Events and Routed Commands in WPF Martin Fowlers description of Presentation Model pattern XAML Guidelines for Creating a Composite UI Guidance on Differences between WPF and Silverlight
Questions?
Rik Robinson
Senior Consultant Wintellect
rrobinson@wintellect.com