Composite WPF
-
Upload
martha-rotter -
Category
Technology
-
view
3.260 -
download
2
Transcript of Composite WPF
Composite Smart Clients with WPFComposite Application Guidance for WPF – “PRISM”
Max KnorDeveloper Evangelist
Microsoft Austria
http://www.knor.net/
2
Agenda
A solution for…
Complex WPF Applications
Developing in Modules
Composite Smart Clients
No introduction to WPF
3
Your WPF Application ?!
4
Your WPF Application ?!
5
Composite Smart Clients
Loosely Coupled
Communication
Extensible
Configurable
Unified
ExperienceShared
User InterfaceCentral Services
(Equilizer, Dolby...)
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, …
7
Architecture of Composite Smart Clients
Module
View Presenter
Model
Main Application
Shell
ShellPresenter
Custom Module Services
Serv
ice
/ D
ep
en
de
ncy
Inje
ctio
n C
on
tain
er
Core-Services
Module-Loader Svc.
RegionRegionRegion
ModuleEnumerator
ModuleLoader
RegionManger
Logging
EventAggregator
8
Starting the Application
Bootstrapper
Application
Initialize Container
Display Shell
Initialize Modules
Shell
Region
Unity Container
ViewModule
Enumerator
Module Loader
Module 1
Module 2
Module 3
Module 4Initialize
Region ManagerSomeClass
Region Manager
9
Dependency Injection mit Unity
this.Container.RegisterType<IMyView, MyView>();
this.Container.RegisterType<IShell, ShellWindow>();
1.) Register types with UnityContainer:
IMyView view = this.Container.Resolve<IMyView>();
2.) Instantiate a new object (resolve instead of new)
public class MyView : UserControl, IMyView
{
public MyView(IUnityContainer container, IShell shell)
{
// container & shell wurden automatisch befüllt
}
}
Constructor is called, dependencies are filled automatically
The Shell
11
The ShellToolbars, ….
Regions
12
Starting the Application
Bootstrapper
Application
Initialize Container
Display ShellShell
Region
Unity Container
Region ManagerSomeClass
demo
Shell & RegionsBootstrapper & Container
Modules
15
Modules
Grouped by UseCases, Functionality, …
No reference to the Shell
Shared Components
Services, Interfaces, … in Shared Libraries
Modules are dynamically loaded
At runtime
16
Starting the Application
Bootstrapper
Application
Initialize Container
Display Shell
Initialize Modules
Shell
Region
Unity Container
Module Enumerator
Module Loader
Module 1
Module 2
Module 3
Module 4Initialize
Region ManagerSomeClass
demo
ModulesModule Loading
18
Dynamic Module Loading
public class MyBootstrapper : UnityPrismBootstrapper
{
...
protected override IModuleEnumerator GetModuleEnumerator()
{
return new StaticModuleEnumerator()
.AddModule(typeof(SomeModule))
.AddModule(typeof(AnotherModule), new[] {"SomeModule")
.AddModule(typeof(YetAnotherModule), new[] {"AnotherModule"
})
}
}
public class MyBootstrapper : UnityPrismBootstrapper{...protected override IModuleEnumerator GetModuleEnumerator(){return new DirectoryLookupModuleEnumerator(@".\Modules");
}}
Searching for modulesin directory
Views & Controllers
20
Implementing the Views
Seperation of UI, logic and data
Presentation Model
Responsible for data loading (from model)
Instantiates the view
View
Binding to PM‘s commands and data
ViewPresentation
ModelModel
21
Starting the Application
Bootstrapper
Application
Initialize Container
Display Shell
Initialize Modules
Shell
Region
Unity Container
View (…)Module
Enumerator
Module Loader
Module 1
Module 2
Module 3
Module 4Initialize
Region ManagerSomeClass
Region Manager
22
public class MyModule : IModule{public void Initialize (IRegionManager manager){
RegisterViewsAndServices();
IRegion orderRegion =manager.GetRegion("OrderRegion");
var myOrderView = new OrderView(myOrder);orderRegion.Add(myOrderView);
}}
Displaying views
Region manager is needed
View is created
Region is retrieved
View is shown
demo
View & PresentationModell
Communikations
25
Loosely coupled communication
Requirements: No direct dependencies
Shared Services
Event Aggregator
Weak Multicast Events
Commands
26
Commands
public interface ICommand{
event EventHandler CanExecuteChanged;bool CanExecute(object parameter);void Execute(object parameter);
}
<Button Command="..." />
MyCommand
Execute() CanExecute()
demo
CommandsEventAggregator
28
Shell Extensibility
Modules can extend the shell with customtoolbars
ShellWindow implements Interface
IExtendableShell
Access via UnityContainer
Modules are only aware of IExtendableShell
Breaking the dependency to shell implementation
29
Shell Extensibility
public ShellWindow : Window, IExtendableShell { .. }ShellWindow.cs:
this.Container.RegisterType<IExtendableShell, ShellWindow();MyBootstrapper.cs:
var shell = this.Container.Resolve<IExtendableShell>();
shell.ShowStatusBarText("bla"); //nur IExtendableShell sichtbar
Im Modul:
IExtendableShell.cs:public interface IExtendableShell
{
void AddToolBarItem(object identifier, string text,
ICommand command);
void RemoveToolBarItems(object identifier);
void ShowStatusBarText(string text);
}
30
Composition Commands
Submit
OrderDetails
Submit
OrderDetails
Submit
OrderDetail
s
Delegate Commands
Composite
Command
Submit
OrderDetails
Submit All
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)