Composite WPF

3,746 views

Published on

Published in: Technology, Art & Photos
  • Be the first to comment

Composite WPF

  1. 1. Composite Smart Clients with WPF Composite Application Guidance for WPF – “PRISM” Max Knor Developer Evangelist Microsoft Austria http://www.knor.net/
  2. 2. Agenda A solution for… Complex WPF Applications Developing in Modules Composite Smart Clients No introduction to WPF 2
  3. 3. Your WPF Application ?! 3
  4. 4. Your WPF Application ?! 4
  5. 5. Composite Smart Clients Configurable Extensible Unified Loosely Coupled Experience Communication Shared Central Services User Interface (Equilizer, Dolby...) 5
  6. 6. WPF Composite Application Guidance Solution Package by Patterns & Practices Team Available in Source http://www.codeplex.com/CompositeWPF/ Reference Implementation (Stock Trader RI) Composite Application Library (Framework) Guidance (Documentation) http://www.codeplex.com/CompositeWPFContrib/ Community Add-Ons OutlookBar, Infragistics Support, … 6
  7. 7. Architecture of Composite Smart Clients Main Application Module-Loader Svc. Service / Dependency Injection Container Shell ModuleEnumerator Shell ModuleLoader Region Region Presenter Region Core-Services RegionManger Module Logging View Presenter EventAggregator Custom Module Model Services 7
  8. 8. Starting the Application Application Bootstrapper Unity Container Initialize Region Manager Container SomeClass Shell Display Shell Region Initialize Modules View Module Module 1 Enumerator Module 2 Module 3 Initialize Module Loader Module 4 8
  9. 9. Dependency Injection mit Unity 1.) Register types with UnityContainer: this.Container.RegisterType<IMyView, MyView>(); this.Container.RegisterType<IShell, ShellWindow>(); 2.) Instantiate a new object (resolve instead of new) IMyView view = this.Container.Resolve<IMyView>(); Constructor is called, dependencies are filled automatically public class MyView : UserControl, IMyView { public MyView(IUnityContainer container, IShell shell) { // container & shell wurden automatisch befüllt } } 9
  10. 10. The Shell
  11. 11. The Shell Toolbars, …. Regions 11
  12. 12. Starting the Application Application Bootstrapper Unity Container Initialize Region Manager Container SomeClass Shell Display Shell Region 12
  13. 13. demo Shell & Regions Bootstrapper & Container
  14. 14. Modules
  15. 15. Modules Grouped by UseCases, Functionality, … No reference to the Shell Shared Components Services, Interfaces, … in Shared Libraries Modules are dynamically loaded At runtime 15
  16. 16. Starting the Application Application Bootstrapper Unity Container Initialize Region Manager Container SomeClass Shell Display Shell Region Initialize Modules Module Module 1 Enumerator Module 2 Module 3 Initialize Module Loader Module 4 16
  17. 17. demo Modules Module Loading
  18. 18. Dynamic Module Loading public class MyBootstrapper : UnityPrismBootstrapper { public class MyBootstrapper : UnityPrismBootstrapper ... { ... protected override IModuleEnumerator GetModuleEnumerator() protected override IModuleEnumerator GetModuleEnumerator() { { return new StaticModuleEnumerator() return new DirectoryLookupModuleEnumerator(@quot;.Modulesquot;); .AddModule(typeof(SomeModule)) } } .AddModule(typeof(AnotherModule), new[] {quot;SomeModulequot;) .AddModule(typeof(YetAnotherModule), new[] {quot;AnotherModulequot; }) } } Searching for modules in directory 18
  19. 19. Views & Controllers
  20. 20. Implementing the Views Seperation of UI, logic and data Presentation View Model Model Presentation Model Responsible for data loading (from model) Instantiates the view View Binding to PM‘s commands and data 20
  21. 21. Starting the Application Application Bootstrapper Unity Container Initialize Region Manager Container SomeClass Shell Display Shell Region Initialize Modules View (…) Module Module 1 Enumerator Module 2 Module 3 Initialize Module Loader Module 4 21
  22. 22. Displaying views Region manager is needed public class MyModule : IModule { public void Initialize (IRegionManager manager) { RegisterViewsAndServices(); Region is retrieved IRegion orderRegion = manager.GetRegion(quot;OrderRegionquot;); var myOrderView = new OrderView(myOrder); orderRegion.Add(myOrderView); } } View is created View is shown 22
  23. 23. demo View & PresentationModell
  24. 24. Communikations
  25. 25. Loosely coupled communication Requirements: No direct dependencies Shared Services Event Aggregator Weak Multicast Events Commands 25
  26. 26. Commands public interface ICommand { event EventHandler CanExecuteChanged; bool CanExecute(object parameter); void Execute(object parameter); } MyCommand <Button Command=quot;...quot; /> Execute() CanExecute() 26
  27. 27. demo Commands EventAggregator
  28. 28. Shell Extensibility Modules can extend the shell with custom toolbars ShellWindow implements Interface IExtendableShell Access via UnityContainer Modules are only aware of IExtendableShell Breaking the dependency to shell implementation 28
  29. 29. Shell Extensibility IExtendableShell.cs: public interface IExtendableShell { void AddToolBarItem(object identifier, string text, ICommand command); void RemoveToolBarItems(object identifier); void ShowStatusBarText(string text); } ShellWindow.cs: public ShellWindow : Window, IExtendableShell { .. } MyBootstrapper.cs: this.Container.RegisterType<IExtendableShell, ShellWindow(); Im Modul: var shell = this.Container.Resolve<IExtendableShell>(); shell.ShowStatusBarText(quot;blaquot;); //nur IExtendableShell sichtbar 29
  30. 30. Composition Commands Composite Submit All Command OrderDetail OrderDetails OrderDetails OrderDetails s Submit Submit Submit Delegate Commands 30
  31. 31. Summary Composite Smart Clients Extensible Architecture Build in a modular way Independent modules enable Parallel Development of modules Flexible deployment Composite Application Guidance Library providing Infrastruktur Tips Interfaces reduce dependencies (z.B.: UI Testing) Event Aggregator can get evil  (event loops) 31
  32. 32. Contact Max Knor Developer Evangelist Microsoft Austria http://www.knor.net/ 32

×