aspect-oriented programming with dependency...
TRANSCRIPT
![Page 1: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/1.jpg)
Aspect-Oriented Programming with Dependency Injection
Mark Seemann
@ploeh
![Page 2: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/2.jpg)
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
![Page 3: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/3.jpg)
Objective
•Single Responsibility Principle
•Open/Closed Principle
•Liskov Substitution Principle
•Interface Segregation Principle
•Dependency Inversion Principle
SOLID
•Don’t Repeat Yourself DRY
![Page 4: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/4.jpg)
Staying SOLID
•Single Responsibility Principle
•Open/Closed Principle
•Liskov Substitution Principle
•Interface Segregation Principle
•Dependency Inversion Principle
SOLID
•Don’t Repeat Yourself DRY
![Page 5: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/5.jpg)
Prerequisite
Program to an interface, not an implementation
- Design Patterns,
1995
![Page 6: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/6.jpg)
Conjecture
• It’s always possible to apply a Decorator to an interface
![Page 7: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/7.jpg)
Using Decorators to add aspects
IFoo
ConcreteFoo
Client
![Page 8: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/8.jpg)
Using Decorators to add aspects
IFoo
AuditingFoo
IFoo
ConcreteFoo
Client
![Page 9: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/9.jpg)
Using Decorators to add aspects
IFoo
SecureFoo
IFoo
AuditingFoo
IFoo
ConcreteFoo
Client
![Page 10: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/10.jpg)
DEMO
Staying SOLID with Decorators
![Page 11: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/11.jpg)
Staying SOLID
•Single Responsibility Principle
•Open/Closed Principle
•Liskov Substitution Principle
•Interface Segregation Principle
•Dependency Inversion Principle
SOLID
•Don’t Repeat Yourself DRY
![Page 12: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/12.jpg)
Staying DRY
•Single Responsibility Principle
•Open/Closed Principle
•Liskov Substitution Principle
•Interface Segregation Principle
•Dependency Inversion Principle
SOLID
•Don’t Repeat Yourself DRY
![Page 13: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/13.jpg)
Dynamic interception
From here on, dynamic interception is required
Commonly supplied by
a DI Container
![Page 14: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/14.jpg)
DI Containers with Interception
Castle Windsor
Unity
Spring.NET LinFu
![Page 15: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/15.jpg)
DEMO
Using a DI Container
![Page 16: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/16.jpg)
Interception
Xyz
![Page 17: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/17.jpg)
Interception
Xyz
IFoo
XyzFoo
Xyz
![Page 18: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/18.jpg)
Interception
Xyz
IFoo
XyzFoo
Xyz
IBar
XyzBar
Xyz
![Page 19: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/19.jpg)
Interception
Xyz
IFoo
XyzFoo
Xyz
IBar
XyzBar
Xyz
IBaz
XyzBaz
Xyz
![Page 20: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/20.jpg)
DEMO
Adding interceptors
![Page 21: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/21.jpg)
Pointcut
Xyz
Abc
Æøå
IFoo
ConcreteFoo
IBar
ConcreteBar
IBaz
ConcreteBaz
![Page 22: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/22.jpg)
Pointcut
Xyz
Abc
Æøå
IFoo
ConcreteFoo
IBar
ConcreteBar
IBaz
ConcreteBaz
Match
![Page 23: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/23.jpg)
DEMO
Adding a pointcut
![Page 24: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/24.jpg)
Objective
•Single Responsibility Principle
•Open/Closed Principle
•Liskov Substitution Principle
•Interface Segregation Principle
•Dependency Inversion Principle
SOLID
•Don’t Repeat Yourself DRY
![Page 25: Aspect-Oriented Programming with Dependency Injectiongotocon.com/dl/...AspectOrientedProgrammingWithDependencyInje… · Objective •Single Responsibility Principle •Open/Closed](https://reader031.vdocuments.us/reader031/viewer/2022022518/5b14bab97f8b9a4e2c8b6205/html5/thumbnails/25.jpg)
Staying SOLID only
requires loose
coupling
Staying DRY requires dynamic
interception