Upload
buidung
View
219
Download
0
Embed Size (px)
Citation preview
Aspect-Oriented Programming with Dependency Injection
Mark Seemann
@ploeh
Cross-Cutting Concerns
Secu
rity
Au
dit
ing
Logg
ing
Cac
hin
g
Met
erin
g
Stab
ility
pat
tern
s
Tran
sact
ion
s
Secu
rity
Au
dit
ing
Logg
ing
Cac
hin
g
Met
erin
g
Stab
ility
pat
tern
s
Tran
sact
ion
s
Objective
•Single Responsibility Principle
•Open/Closed Principle
•Liskov Substitution Principle
•Interface Segregation Principle
•Dependency Inversion Principle
SOLID
•Don’t Repeat Yourself DRY
Staying SOLID
•Single Responsibility Principle
•Open/Closed Principle
•Liskov Substitution Principle
•Interface Segregation Principle
•Dependency Inversion Principle
SOLID
•Don’t Repeat Yourself DRY
Prerequisite
Program to an interface, not an implementation
- Design Patterns,
1995
Conjecture
• It’s always possible to apply a Decorator to an interface
Using Decorators to add aspects
IFoo
ConcreteFoo
Client
Using Decorators to add aspects
IFoo
AuditingFoo
IFoo
ConcreteFoo
Client
Using Decorators to add aspects
IFoo
SecureFoo
IFoo
AuditingFoo
IFoo
ConcreteFoo
Client
DEMO
Staying SOLID with Decorators
Staying SOLID
•Single Responsibility Principle
•Open/Closed Principle
•Liskov Substitution Principle
•Interface Segregation Principle
•Dependency Inversion Principle
SOLID
•Don’t Repeat Yourself DRY
Staying DRY
•Single Responsibility Principle
•Open/Closed Principle
•Liskov Substitution Principle
•Interface Segregation Principle
•Dependency Inversion Principle
SOLID
•Don’t Repeat Yourself DRY
Dynamic interception
From here on, dynamic interception is required
Commonly supplied by
a DI Container
DI Containers with Interception
Castle Windsor
Unity
Spring.NET LinFu
DEMO
Using a DI Container
Interception
Xyz
Interception
Xyz
IFoo
XyzFoo
Xyz
Interception
Xyz
IFoo
XyzFoo
Xyz
IBar
XyzBar
Xyz
Interception
Xyz
IFoo
XyzFoo
Xyz
IBar
XyzBar
Xyz
IBaz
XyzBaz
Xyz
DEMO
Adding interceptors
Pointcut
Xyz
Abc
Æøå
IFoo
ConcreteFoo
IBar
ConcreteBar
IBaz
ConcreteBaz
Pointcut
Xyz
Abc
Æøå
IFoo
ConcreteFoo
IBar
ConcreteBar
IBaz
ConcreteBaz
Match
DEMO
Adding a pointcut
Objective
•Single Responsibility Principle
•Open/Closed Principle
•Liskov Substitution Principle
•Interface Segregation Principle
•Dependency Inversion Principle
SOLID
•Don’t Repeat Yourself DRY
Staying SOLID only
requires loose
coupling
Staying DRY requires dynamic
interception