Download presentation
Presentation is loading. Please wait.
Published byCharlotte Chambers Modified over 9 years ago
2
Claudio Lassala Software Developer EPS Software / CODE Magazine Session Code: DEV 201
3
Who Am I? Claudio Lassala Blog: ClaudioLassala.spaces.live.com claudio@eps-software.com twitter.com/ClaudioLassala Microsoft MVP for the last 9 years INETA Speaker International Speaker and Writer Virtual Brown Bag Meeting Virtual Brown Bag Meeting Developer @ EPS Software
4
About EPS Software Custom Software Development Consulting / Mentoring Training WPF.NET CODE Magazine
5
What is a “Composite” Application? Application that may Use different data sources (web services, local data..) Combine multiple modules Have composite “views” (screens)
6
Composite Application Samples
7
The Challenge
8
Composite Application Guidance for WPF and Silverlight
9
Prism: What’s in the box? Prism – Composite Client Application Guidance for WPF and Silverlight Composite Application Library (CAL) Reference Implementation (StockTrader) Documentation Quick-Starts & How-To’s Community – CodePlex www.microsoft.com/CompositeWPF
10
Prism Core Concepts Module Loading UI Composition View Injection and View Discovery Events Commands Optional (but recommended) Bootstrapper DI/IoC Container Separated Presentation
11
DI/IoC Container var container = new UnityContainer() container.RegisterType (); var view = container.Resolve (); public class Shell { public Shell(ISomeService someService) { }
12
Bootstrapper public partial class MyAppBootstrapper : UnityBootstrapper { protected override IModuleCatalog GetModuleCatalog() { // register modules with catalog… } protected override void ConfigureContainer() { // Register types with container… } protected override DependencyObject CreateShell() { // resolve shell and show it… }
13
Separated Presentation Patterns Supervising Controller Presentation Model / Model-View-ViewModel PresenterPresenter ModelModel ViewView ViewModelViewModelModelModelViewView
14
Module Loading Implement IModule Tell Prism how to go find it
15
Implementing IModule public class ModuleA : IModule { private readonly IRegionManager regionManager; public ModuleA(IRegionManager regionManager) { this.regionManager = regionManager; } public void Initialize() { this.regionManager.Regions["MainRegion"].Add(new DefaultViewA()); }
16
Loading Modules ModuleCatalog catalog = new ModuleCatalog(); catalog.AddModule(typeof (ModuleA), "ModuleD").AddModule(typeof (ModuleD), "ModuleB").AddModule(typeof (ModuleC), InitializationMode.OnDemand); private void SomeMethod(IModuleManager moduleManager) { moduleManager.LoadModule("ModuleC"); }
17
UI Composition View Injection View Discovery Region Manager
18
Definition Regions <ContentControl cal:RegionManager.RegionName = "ToolbarRegion" /> <ItemsControl cal:RegionManager.RegionName = "MainRegion" /> ToolbarRegionToolbarRegion MainRegionMainRegion
19
View Discovery public void Initialize() { this.regionManager.RegisterViewWithRegion("MainRegion", () => container.Resolve ().View); }
20
View Injection public void Initialize() { var presenter = this.container.Resolve (); IRegion mainRegion = this.regionManager.Regions["MainRegion"]; mainRegion.Add(presenter.View); }
21
Commands Delegate Command Composite Command
22
Hooking Up Commands // Delegate Command <Button Content="Save" Command="{Binding SaveOrderCommand}" /> // Composite Command <Button Content="Save All" Command="{x:Static inf:OrdersCommands.SaveAllOrdersCommand}" />
23
Handling Delegate Command public DelegateCommand SaveOrderCommand { get; private set; } public OrderPresentationModel() { this.SaveOrderCommand = new DelegateCommand (this.Save, this.CanSave); } private void Save(Order order) { // Save the order here. } private bool CanSave(Order order) { return order.IsValid(); }
24
Defining Composite Commands public static class OrdersCommands { public static CompositeCommand SaveAllOrdersCommand = new CompositeCommand(); } public class OrdersCommandProxy { public virtual CompositeCommand SaveAllOrdersCommand { get { return OrdersCommands.SaveAllOrdersCommand; } }
25
Wiring Composite Commands commandProxy.SaveAllOrdersCommand.RegisterCommand( orderPresentationModel.SaveOrderCommand); Save All OrderOrder SaveSave OrderOrder SaveSave OrderOrder SaveSave
26
Events Loosely Coupled Events Subscribers and Publishers don't know about it other Threading Support Subscription Filter Weak Reference
27
Defining Composite Events public class FundAddedEvent : CompositePresentationEvent { } public class FundOrder { public string CustomerId { get; set; } public string TickerSymbol { get; set; } }
28
Publishing Composite Events public AddFundPresenter(IEventAggregator eventAggregator) { this.eventAggregator = eventAggregator; } void AddFund(object sender, EventArgs e) { FundOrder fundOrder = new FundOrder(); fundOrder.CustomerId = View.Customer; fundOrder.TickerSymbol = View.Fund; eventAggregator.GetEvent ().Publish(fundOrder); }
29
Subscribing To Composite Events var fundAddedEvent = eventAggregator.GetEvent (); fundAddedEvent.Subscribe(FundAddedEventHandler); public void FundAddedEventHandler(FundOrder fundOrder) { // process fund order… }
30
Subscribing To Composite Events var fundAddedEvent = eventAggregator.GetEvent (); fundAddedEvent.Subscribe(FundAddedEventHandler, ThreadOption.UIThread, false, FundOrderFilter); public void FundAddedEventHandler(FundOrder fundOrder) { // process fund order… } public bool FundOrderFilter(FundOrder fundOrder) { return fundOrder.CustomerId == _customerId; }
32
The Shell Always put some thought into what elements the Shell should have What the elements look like can be defined or changed later Toolbar Region Navigation Region Extra Info Region Main Region
33
Infrastructure An “infrastructure” project should contain cross- cutting plumbing/features That is, anything required by the application as a whole, or required by more than one module Key abstractions go there
34
Modules Usually, one project per module Single Project could have multiple modules organized by namespace Harder to manage dependencies between modules Compiling separate projects into a single DLL is easy; going the other way around, not so much! Views, ViewModels, Controllers, “application services”…
35
Looking at a Composite Application
37
Call to Action Poke around this sample application Read Prism’s documentation
39
www.microsoft.com/teched Sessions On-Demand & Community http://microsoft.com/technet Resources for IT Professionals http://microsoft.com/msdn Resources for Developers www.microsoft.com/learning Microsoft Certification & Training Resources Resources Required Slide Speakers, TechEd 2009 is not producing a DVD. Please announce that attendees can access session recordings at TechEd Online. Required Slide Speakers, TechEd 2009 is not producing a DVD. Please announce that attendees can access session recordings at TechEd Online.
40
More Resources See my article on CODE magazine (2009 Jul/Aug) www.microsoft.com/CompositeWPF
41
Complete an evaluation on CommNet and enter to win an Xbox 360 Elite!
42
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Required Slide
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.