![Page 1: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/1.jpg)
Inspiring people toshareAOP and Dependency Injection
Robert Lemke | TYPO3 Association
![Page 2: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/2.jpg)
AOP and Dependency Injection
Overview
About me, the flow and buzz ...
Unit Testing
Dependency Injection
Aspect-Oriented Programming
![Page 3: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/3.jpg)
AOP and Dependency Injection
About me
Robert Lemke, born 27/05/1976
beautiful code evangelist
"chief architect" of TYPO3 5.0 and FLOW3
coffee junkie
married, no children, 1 espresso machine
![Page 4: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/4.jpg)
AOP and Dependency Injection
Robert Lemke, born 27/05/1976
beautiful code evangelist
"chief architect" of TYPO3 5.0 and FLOW3
coffee junkie
married, no children, 1 espresso machine
HINTAbout me
![Page 5: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/5.jpg)
AOP and Dependency Injection
About FLOW3
Offspring from the development of TYPO3 5.0
PHP-based enterprise application framework
Enterprise: Information intensive applications with focus on domain logic
FLOW3 is ready to go, with a default layer architecture, object management, security etc.
Special support for Domain-Driven Design
![Page 6: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/6.jpg)
AOP and Dependency Injection
About the buzz
AOP, DI, DDD, TDD, XP, ... ?
YAGNI ?
IMYLME !
![Page 7: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/7.jpg)
AOP and Dependency Injection
The Demo Package
Demo
![Page 8: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/8.jpg)
![Page 9: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/9.jpg)
AOP and Dependency Injection
Unit Testing
Testing is important (as if you didn't know that)
But not every code can be tested
Dependencies make your developer's life hard
![Page 10: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/10.jpg)
AOP and Dependency Injection
Unit Testing
Dependencies
Problem: Classes explicitly refer to other classes:
![Page 11: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/11.jpg)
AOP and Dependency Injection
Unit Testing
Dependencies
Try to test this class:
![Page 12: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/12.jpg)
AOP and Dependency Injection
Unit Testing
Dependencies
Unit Testing: You want to test a small unit
You don't want to test
The Simple File Logger
The Card Repository
![Page 13: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/13.jpg)
AOP and Dependency Injection
Unit Testing
Dependencies
Unit Testing: You want to test a small unit
You want to test
if the action returns a string representation of the random card it gets from the repository
![Page 14: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/14.jpg)
AOP and Dependency Injection
Dependency Injection
A class doesn't ask for the instance of another class but gets it injected
This methodology is referred to as the "Hollywood Principle":"Don't call us, we'll call you"
Enforces loose coupling and high cohesion
Allows you to mock collaborators
Makes you a better programmer
![Page 15: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/15.jpg)
AOP and Dependency Injection
Dependency Injection
Constructor without Dependency Injection
![Page 16: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/16.jpg)
AOP and Dependency Injection
Dependency Injection
Component with Constructor Injection
![Page 17: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/17.jpg)
AOP and Dependency Injection
Dependency Injection
Component with Setter Injection
![Page 18: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/18.jpg)
AOP and Dependency Injection
Dependency Injection
Component Manager
Manages the whole object lifecycle
Provides so-called "IoC Container"
Components: objects
Components can be configured
![Page 19: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/19.jpg)
AOP and Dependency Injection
Dependency Injection
Autowiring
FLOW3 tries to autowire constructor arguments and arguments of inject* methods
The type of the component to be injected is determined by the argument type (type hinting)
Autowiring does not work with Setter Injection through regular setters (set* methods)
Dependencies are only autowired if no argument is passed explicitly
![Page 20: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/20.jpg)
AOP and Dependency Injection
Dependency Injection
Component scope
Component objects always live in a certain scope
Currently supported scopes are:
Singleton - Only one instance exists during one script run
Prototype - Multiple instances are possible
![Page 21: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/21.jpg)
AOP and Dependency Injection
Dependency Injection
Component scope
The scope can be defined through
an annotation in the component class (recommended)
through the component configuration in a Components.php file
The default scope is "Singleton"
![Page 22: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/22.jpg)
AOP and Dependency Injection
Components
Component scope
![Page 23: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/23.jpg)
AOP and Dependency Injection
Components
Creating Prototypes
Dependency Injection can be used in almost any case, there's no need to call getComponent()
But what if you need to instantiate a component within a method?
![Page 24: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/24.jpg)
AOP and Dependency Injection
Components
Creating Prototypes
Solution A: Call getComponent()
![Page 25: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/25.jpg)
AOP and Dependency Injection
Components
Creating Prototypes
Solution B: Call a factory method
![Page 26: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/26.jpg)
AOP and Dependency Injection
Aspect Oriented Programming
AOP is a programming paradigm
complements OOP by separating concerns to improve modularization
OOP modularizes concerns: methods, classes, packages
AOP addresses cross-cutting concerns
![Page 27: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/27.jpg)
AOP and Dependency Injection
Aspect Oriented Programming
Cross-cutting concerns
Presentation
Domain
Data source
![Page 28: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/28.jpg)
AOP and Dependency Injection
Aspect Oriented Programming
Cross-cutting concerns
Presentation
Domain
Data source
The concerns
live here
![Page 29: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/29.jpg)
AOP and Dependency Injection
Aspect Oriented Programming
Cross-cutting concerns
Some Domain Model
Security
Logging
CONCERNSX-ING
![Page 30: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/30.jpg)
AOP and Dependency Injection
PHP's missing features
With AOP you can
centralize and cleanly separate your concerns
intercept any method call
add new behavior to legacy code without touching it
do a lot of dirty tricks
Aspect Oriented Programming
![Page 31: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/31.jpg)
AOP and Dependency Injection
Aspect Oriented Programming
Some Vocabulary
Advice
encapsulated code, to be re-used
Joinpoint
places in the code where advice can be applied
Pointcut
identifies set of joinpoints where advice should be applied
Aspect
groups advices and pointcuts
![Page 32: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/32.jpg)
AOP and Dependency Injection
The AOP Hello World Classic Demo
Demo
![Page 33: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/33.jpg)
![Page 34: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/34.jpg)
AOP and Dependency Injection
Aspect Oriented Programming
Applications for AOP
Logging
Security
Transactions
Persistence
Statistics
In the Domain Layer
![Page 35: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/35.jpg)
AOP and Dependency Injection
Aspect Oriented Programming
Behind the Scenes
Dynamic Proxy Classes
Component Manager delivers the right implementation
Only works if "new" is not used
![Page 36: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/36.jpg)
AOP and Dependency Injection
More ...
![Page 37: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/37.jpg)
AOP and Dependency Injection
More
Where can I get FLOW3?
From our Subversion repository:
https://svn.typo3.org/FLOW3/Distribution/trunk/
![Page 38: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/38.jpg)
AOP and Dependency Injection
More ...
DEV3
![Page 39: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/39.jpg)
AOP and Dependency Injection
More ...
AOP Browser
![Page 40: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/40.jpg)
AOP and Dependency Injection
More ...
Known Issues
FLOW3 (or rather PHP) currently causesApache crashes - why ever ...
Tests consume a lot of memory(> 400 MB)
Access is comparably slow even inProduction context (~ 3 req/s) andneeds much memory (~ 20 MB)
Many aspects are work in progress andneither optimized nor finished
![Page 41: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/41.jpg)
AOP and Dependency Injection
Links
FLOW3 Websitehttp://flow3.typo3.org
TYPO3 Forgehttp://forge.typo3.org
T3CASThttp://typo3.org/podcasts/robert
![Page 42: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/42.jpg)
AOP and Dependency Injection
So long and thanks for the fish
Questions
![Page 43: Aspect-Oriented Programming and Depedency Injection](https://reader033.vdocument.in/reader033/viewer/2022052505/555a8d60d8b42abb628b532f/html5/thumbnails/43.jpg)