composite ui application block - brad wilson · july 24, 2005 portland code camp 1.0 dependency...

25
July 24, 2005 Portland Code Camp 1.0 Composite UI Application Block Brad Wilson Microsoft patterns & practices [email protected] http://msdn.microsoft.com/practices/ http://bradwilson.typepad.com/

Upload: others

Post on 19-Jun-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

Composite UI

Application Block

Brad Wilson

Microsoft patterns & practices

[email protected]

http://msdn.microsoft.com/practices/

http://bradwilson.typepad.com/

Page 2: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

What is a Composite

Smart Client?

Page 3: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

Page 4: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

Technology

Page 5: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

Dependency Injection

The "old way":

Components have

intimate knowledge

of services

public class Component

{

private Service svc = new Service();

}

Component

Service

Page 6: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

Dependency Injection

In the right direction:

Component uses

services by interfaces

and factories

public class Component

{

private IService svc = ServiceFactory.GetService();

}

Component

Service

IService

Page 7: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

Dependency Injection

The "CAB way":

Dependencies are

injected at runtime

instead of compile time

public class Component

{

[ServiceDependency]

private IService svc;

}Container

Component

Service

IService

Page 8: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

Demo

Dependency Injection

Page 9: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

Event Broker

The "old way":

Events are wired up

at compile time

public class Sender {

public event EventHandler evt;

}

public class Listener {

mySender.evt += new EventHandler(myHandler);

}

Listener

Sender

Page 10: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

Event Broker

The "CAB way":

Events are wired up

at runtime

public class Sender {

[EventPublication("topic://Sender/event1")]

public event EventHandler evt;

}

public class Listener {

[EventSubscription("topic://Sender/event1")]

private void MyHandler(object sender, EventArgs e)

}

Container

Listener Sender

Page 11: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

Event Broker

Multiple subscribers

Sender

Listener 2

Listener 1

Page 12: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

Event Broker

Multiple publishers

Against multiple subscribers, too

Sender 1

Sender 2

Listener 1

topic://sender/event

topic://sender/event

Listener 2

Page 13: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

Demo

Event Broker

Page 14: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

Command Dispatching

De-couples UI elements from command

handlers

Architecture similar to Event Broker

Page 15: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

Demo

Command Dispatching

Page 16: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

Modules

Isolated, reusable functionality

Loosely coupled teams

Role-based modules

Application

Shell

Module

Module

Module

Page 17: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

Demo

Modules

Page 18: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

CAB Application ArchitectureApplication Host

Shell

Module A

Services

Monitors

WorkItem A

Services Monitors

Controller A

View A

Controller B

View B

State

Module B

WorkItem C

Services Monitors State

Controller A

View A

Controller B

View B

Page 19: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

CAB Architecture

Component Model

Composite UI

Composite UI

(WinForms)

Page 20: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

CAB Architecture

Component Model

Composite UI

Composite UI

(WinForms)

Composite UI

(Avalon)

Composite UI

(3rd party)

Page 21: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

Views & Controllers

Views present model data to the user

Controllers contain the business logic

Automatically wired up by the container

A view has one and only one controller

A controller may control many views

Page 22: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

Work Item

Represents a use case in the system

Specialized container for

Model Data

Views

Controllers

Workspaces

Services

Key point of reusability

Model

Model

Model

View Ctrlr

Svc

Page 23: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

Workspaces

Workspaces are canvases onto which you can paint your views

For Windows Forms, we ship:

WindowWorkspace

MdiWorkspace

ZoneWorkspace

TabWorkspace

DeckWorkspace

Page 24: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

Demo

Bank Teller QuickStart

Page 25: Composite UI Application Block - Brad Wilson · July 24, 2005 Portland Code Camp 1.0 Dependency Injection The "old way": Components have intimate knowledge of services public class

July 24, 2005 Portland Code Camp 1.0

Q & A