SlideShare ist ein Scribd-Unternehmen logo
1 von 43
Downloaden Sie, um offline zu lesen
Robert Lemke | TYPO3 Association

AOP and Dependency Injection
Overview
     About me, the flow and buzz ...
     Unit Testing
     Dependency Injection
     Aspect-Oriented Programming




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




AOP and Dependency Injection
About me                                        HINT
     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




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




AOP and Dependency Injection
About the buzz
     AOP, DI, DDD, TDD, XP, ... ?

     YAGNI ?

     IMYLME !




AOP and Dependency Injection
The Demo Package



                        Demo



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




AOP and Dependency Injection
Unit Testing


Dependencies
        Problem: Classes explicitly refer to other classes:




AOP and Dependency Injection
Unit Testing


Dependencies
        Try to test this class:




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




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




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




AOP and Dependency Injection
Dependency Injection


Constructor without Dependency Injection




AOP and Dependency Injection
Dependency Injection


Component with Constructor Injection




AOP and Dependency Injection
Dependency Injection


Component with Setter Injection




AOP and Dependency Injection
Dependency Injection


Component Manager
       Manages the whole object lifecycle

       Provides so-called "IoC Container"

       Components: objects

       Components can be configured




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




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




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"




AOP and Dependency Injection
Components


Component scope




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?




AOP and Dependency Injection
Components


Creating Prototypes
      Solution A: Call getComponent()




AOP and Dependency Injection
Components


Creating Prototypes
      Solution B: Call a factory method




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




AOP and Dependency Injection
Aspect Oriented Programming


Cross-cutting concerns

                              Presentation

                                Domain

                              Data source




AOP and Dependency Injection
Aspect Oriented Programming


Cross-cutting concerns

                              Presentation   The concerns
                                               live here

                                Domain

                              Data source




AOP and Dependency Injection
Aspect Oriented Programming


Cross-cutting concerns


                              Some Domain Model


                                  Security        CONCERNS
                                  Logging           X-ING



AOP and Dependency Injection
Aspect Oriented Programming


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




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



AOP and Dependency Injection
The AOP Hello World Classic Demo



                        Demo



AOP and Dependency Injection
Aspect Oriented Programming


Applications for AOP
       Logging

       Security

       Transactions

       Persistence

       Statistics

       In the Domain Layer




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




AOP and Dependency Injection
More ...




AOP and Dependency Injection
More


Where can I get FLOW3?
  From our Subversion repository:

  https://svn.typo3.org/FLOW3/Distribution/trunk/




AOP and Dependency Injection
More ...


DEV3




AOP and Dependency Injection
More ...


AOP Browser




AOP and Dependency Injection
More ...


Known Issues
           FLOW3 (or rather PHP) currently causes
           Apache crashes - why ever ...

           Tests consume a lot of memory
           (> 400 MB)

           Access is comparably slow even in
           Production context (~ 3 req/s) and
           needs much memory (~ 20 MB)

           Many aspects are work in progress and
           neither optimized nor finished




AOP and Dependency Injection
Links
     FLOW3 Website
     http://flow3.typo3.org

     TYPO3 Forge
     http://forge.typo3.org

     T3CAST
     http://typo3.org/podcasts/robert




AOP and Dependency Injection
So long and thanks for the fish


Questions




AOP and Dependency Injection
Aspect-Oriented Programming and Depedency Injection

Weitere ähnliche Inhalte

Was ist angesagt?

[2016/2017] Architectural languages
[2016/2017] Architectural languages[2016/2017] Architectural languages
[2016/2017] Architectural languagesIvano Malavolta
 
OOP Comparative Study
OOP Comparative StudyOOP Comparative Study
OOP Comparative StudyDarren Tan
 
PRIME OOPSLA12 paper
PRIME OOPSLA12 paperPRIME OOPSLA12 paper
PRIME OOPSLA12 paperEran Yahav
 
Chapter 5: Names, Bindings and Scopes (review Questions and Problem Set)
Chapter 5: Names, Bindings and Scopes (review Questions and Problem Set)Chapter 5: Names, Bindings and Scopes (review Questions and Problem Set)
Chapter 5: Names, Bindings and Scopes (review Questions and Problem Set)Farwa Ansari
 
Java chapter 3 - OOPs concepts
Java chapter 3 - OOPs conceptsJava chapter 3 - OOPs concepts
Java chapter 3 - OOPs conceptsMukesh Tekwani
 
Chapter 9 & chapter 10 solutions
Chapter 9 & chapter 10 solutionsChapter 9 & chapter 10 solutions
Chapter 9 & chapter 10 solutionsSaeed Iqbal
 
Java quick reference
Java quick referenceJava quick reference
Java quick referenceArthyR3
 
Python Programming language
Python Programming languagePython Programming language
Python Programming languageHadeelAlbedah
 
The road ahead for architectural languages [ACVI 2016]
The road ahead for architectural languages [ACVI 2016]The road ahead for architectural languages [ACVI 2016]
The road ahead for architectural languages [ACVI 2016]Ivano Malavolta
 
[2015/2016] Architectural languages
[2015/2016] Architectural languages[2015/2016] Architectural languages
[2015/2016] Architectural languagesIvano Malavolta
 
Finding latent code errors via machine learning over program ...
Finding latent code errors via machine learning over program ...Finding latent code errors via machine learning over program ...
Finding latent code errors via machine learning over program ...butest
 
Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming languageVasavi College of Engg
 
SAP ABAP using OOPS - JH Softech
SAP ABAP using OOPS - JH SoftechSAP ABAP using OOPS - JH Softech
SAP ABAP using OOPS - JH SoftechVikram P Madduri
 
WhitePaperTemplate
WhitePaperTemplateWhitePaperTemplate
WhitePaperTemplateJo Marques
 
Introduction to c_sharp
Introduction to c_sharpIntroduction to c_sharp
Introduction to c_sharpHEM Sothon
 

Was ist angesagt? (20)

[2016/2017] Architectural languages
[2016/2017] Architectural languages[2016/2017] Architectural languages
[2016/2017] Architectural languages
 
OOP Comparative Study
OOP Comparative StudyOOP Comparative Study
OOP Comparative Study
 
PRIME OOPSLA12 paper
PRIME OOPSLA12 paperPRIME OOPSLA12 paper
PRIME OOPSLA12 paper
 
Chapter 5: Names, Bindings and Scopes (review Questions and Problem Set)
Chapter 5: Names, Bindings and Scopes (review Questions and Problem Set)Chapter 5: Names, Bindings and Scopes (review Questions and Problem Set)
Chapter 5: Names, Bindings and Scopes (review Questions and Problem Set)
 
Java chapter 3 - OOPs concepts
Java chapter 3 - OOPs conceptsJava chapter 3 - OOPs concepts
Java chapter 3 - OOPs concepts
 
Chapter 9 & chapter 10 solutions
Chapter 9 & chapter 10 solutionsChapter 9 & chapter 10 solutions
Chapter 9 & chapter 10 solutions
 
Java quick reference
Java quick referenceJava quick reference
Java quick reference
 
Introduction to programming languages part 2
Introduction to programming languages   part 2Introduction to programming languages   part 2
Introduction to programming languages part 2
 
Python Programming language
Python Programming languagePython Programming language
Python Programming language
 
Ijetcas14 385
Ijetcas14 385Ijetcas14 385
Ijetcas14 385
 
The road ahead for architectural languages [ACVI 2016]
The road ahead for architectural languages [ACVI 2016]The road ahead for architectural languages [ACVI 2016]
The road ahead for architectural languages [ACVI 2016]
 
report
reportreport
report
 
Handout#05
Handout#05Handout#05
Handout#05
 
C Course Material0209
C Course Material0209C Course Material0209
C Course Material0209
 
[2015/2016] Architectural languages
[2015/2016] Architectural languages[2015/2016] Architectural languages
[2015/2016] Architectural languages
 
Finding latent code errors via machine learning over program ...
Finding latent code errors via machine learning over program ...Finding latent code errors via machine learning over program ...
Finding latent code errors via machine learning over program ...
 
Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming language
 
SAP ABAP using OOPS - JH Softech
SAP ABAP using OOPS - JH SoftechSAP ABAP using OOPS - JH Softech
SAP ABAP using OOPS - JH Softech
 
WhitePaperTemplate
WhitePaperTemplateWhitePaperTemplate
WhitePaperTemplate
 
Introduction to c_sharp
Introduction to c_sharpIntroduction to c_sharp
Introduction to c_sharp
 

Andere mochten auch

Current State of TYPO3 Phoenix (T3CON10)
Current State of TYPO3 Phoenix (T3CON10)Current State of TYPO3 Phoenix (T3CON10)
Current State of TYPO3 Phoenix (T3CON10)Robert Lemke
 
Fluent Development with FLOW3 1.0
Fluent Development with FLOW3 1.0Fluent Development with FLOW3 1.0
Fluent Development with FLOW3 1.0Robert Lemke
 
TYPO3 5.0 - Der aktuelle Stand der Zukunft
TYPO3 5.0 - Der aktuelle Stand der ZukunftTYPO3 5.0 - Der aktuelle Stand der Zukunft
TYPO3 5.0 - Der aktuelle Stand der ZukunftJochen Rau
 
T3DD06 TYPO3 5.0 Brainstorming Results
T3DD06 TYPO3 5.0 Brainstorming ResultsT3DD06 TYPO3 5.0 Brainstorming Results
T3DD06 TYPO3 5.0 Brainstorming ResultsRobert Lemke
 
The Secret Recipe of a Juicy M
The Secret Recipe of a Juicy MThe Secret Recipe of a Juicy M
The Secret Recipe of a Juicy MRobert Lemke
 
Facilitating the Elephant carpaccio exercise
Facilitating the Elephant carpaccio exerciseFacilitating the Elephant carpaccio exercise
Facilitating the Elephant carpaccio exercisePeter Antman
 
IPC16: A Practical Introduction to Kubernetes
IPC16: A Practical Introduction to Kubernetes IPC16: A Practical Introduction to Kubernetes
IPC16: A Practical Introduction to Kubernetes Robert Lemke
 

Andere mochten auch (7)

Current State of TYPO3 Phoenix (T3CON10)
Current State of TYPO3 Phoenix (T3CON10)Current State of TYPO3 Phoenix (T3CON10)
Current State of TYPO3 Phoenix (T3CON10)
 
Fluent Development with FLOW3 1.0
Fluent Development with FLOW3 1.0Fluent Development with FLOW3 1.0
Fluent Development with FLOW3 1.0
 
TYPO3 5.0 - Der aktuelle Stand der Zukunft
TYPO3 5.0 - Der aktuelle Stand der ZukunftTYPO3 5.0 - Der aktuelle Stand der Zukunft
TYPO3 5.0 - Der aktuelle Stand der Zukunft
 
T3DD06 TYPO3 5.0 Brainstorming Results
T3DD06 TYPO3 5.0 Brainstorming ResultsT3DD06 TYPO3 5.0 Brainstorming Results
T3DD06 TYPO3 5.0 Brainstorming Results
 
The Secret Recipe of a Juicy M
The Secret Recipe of a Juicy MThe Secret Recipe of a Juicy M
The Secret Recipe of a Juicy M
 
Facilitating the Elephant carpaccio exercise
Facilitating the Elephant carpaccio exerciseFacilitating the Elephant carpaccio exercise
Facilitating the Elephant carpaccio exercise
 
IPC16: A Practical Introduction to Kubernetes
IPC16: A Practical Introduction to Kubernetes IPC16: A Practical Introduction to Kubernetes
IPC16: A Practical Introduction to Kubernetes
 

Ähnlich wie Aspect-Oriented Programming and Depedency Injection

Performance analysis of synchronisation problem
Performance analysis of synchronisation problemPerformance analysis of synchronisation problem
Performance analysis of synchronisation problemharshit200793
 
springtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfspringtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfBruceLee275640
 
Spring basics for freshers
Spring basics for freshersSpring basics for freshers
Spring basics for freshersSwati Bansal
 
Aspect oriented programming in .Net
Aspect oriented programming in .NetAspect oriented programming in .Net
Aspect oriented programming in .NetPaul Fryer
 
Aop With Post Sharp
Aop With Post SharpAop With Post Sharp
Aop With Post SharpLance Zhang
 
Spring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggetsSpring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggetsVirtual Nuggets
 
Aspect Oriented Software Development
Aspect Oriented Software DevelopmentAspect Oriented Software Development
Aspect Oriented Software DevelopmentJignesh Patel
 
Introduction to Aspect Oriented Programming by Donald Belcham
Introduction to Aspect Oriented Programming by Donald BelchamIntroduction to Aspect Oriented Programming by Donald Belcham
Introduction to Aspect Oriented Programming by Donald Belcham.NET Conf UY
 
IPC07 Talk - Beautiful Code with AOP and DI
IPC07 Talk - Beautiful Code with AOP and DIIPC07 Talk - Beautiful Code with AOP and DI
IPC07 Talk - Beautiful Code with AOP and DIRobert Lemke
 
API Docs Made Right / RAML - Swagger rant
API Docs Made Right / RAML - Swagger rantAPI Docs Made Right / RAML - Swagger rant
API Docs Made Right / RAML - Swagger rantVladimir Shulyak
 
Using Spring Boot Effectively in Cloud Foundry
Using Spring Boot Effectively in Cloud FoundryUsing Spring Boot Effectively in Cloud Foundry
Using Spring Boot Effectively in Cloud FoundryJosh Ghiloni
 

Ähnlich wie Aspect-Oriented Programming and Depedency Injection (20)

Performance analysis of synchronisation problem
Performance analysis of synchronisation problemPerformance analysis of synchronisation problem
Performance analysis of synchronisation problem
 
WoMakersCode 2016 - Shit Happens
WoMakersCode 2016 -  Shit HappensWoMakersCode 2016 -  Shit Happens
WoMakersCode 2016 - Shit Happens
 
springtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfspringtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdf
 
Spring basics for freshers
Spring basics for freshersSpring basics for freshers
Spring basics for freshers
 
Aspect oriented programming in .Net
Aspect oriented programming in .NetAspect oriented programming in .Net
Aspect oriented programming in .Net
 
Aop With Post Sharp
Aop With Post SharpAop With Post Sharp
Aop With Post Sharp
 
Spring Framework Rohit
Spring Framework RohitSpring Framework Rohit
Spring Framework Rohit
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Spring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggetsSpring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggets
 
Intro To AOP
Intro To AOPIntro To AOP
Intro To AOP
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Aspect Oriented Software Development
Aspect Oriented Software DevelopmentAspect Oriented Software Development
Aspect Oriented Software Development
 
Spring fundamentals
Spring fundamentalsSpring fundamentals
Spring fundamentals
 
Spring ppt
Spring pptSpring ppt
Spring ppt
 
Api tools overview
Api tools overviewApi tools overview
Api tools overview
 
Introduction to Aspect Oriented Programming by Donald Belcham
Introduction to Aspect Oriented Programming by Donald BelchamIntroduction to Aspect Oriented Programming by Donald Belcham
Introduction to Aspect Oriented Programming by Donald Belcham
 
Introduction To AOP
Introduction To AOPIntroduction To AOP
Introduction To AOP
 
IPC07 Talk - Beautiful Code with AOP and DI
IPC07 Talk - Beautiful Code with AOP and DIIPC07 Talk - Beautiful Code with AOP and DI
IPC07 Talk - Beautiful Code with AOP and DI
 
API Docs Made Right / RAML - Swagger rant
API Docs Made Right / RAML - Swagger rantAPI Docs Made Right / RAML - Swagger rant
API Docs Made Right / RAML - Swagger rant
 
Using Spring Boot Effectively in Cloud Foundry
Using Spring Boot Effectively in Cloud FoundryUsing Spring Boot Effectively in Cloud Foundry
Using Spring Boot Effectively in Cloud Foundry
 

Mehr von Robert Lemke

Neos Content Repository – Git for content
Neos Content Repository – Git for contentNeos Content Repository – Git for content
Neos Content Repository – Git for contentRobert Lemke
 
A General Purpose Docker Image for PHP
A General Purpose Docker Image for PHPA General Purpose Docker Image for PHP
A General Purpose Docker Image for PHPRobert Lemke
 
Scaleable PHP Applications in Kubernetes
Scaleable PHP Applications in KubernetesScaleable PHP Applications in Kubernetes
Scaleable PHP Applications in KubernetesRobert Lemke
 
Flownative Beach - Neos Meetup Hamburg 2022
Flownative Beach - Neos Meetup Hamburg 2022Flownative Beach - Neos Meetup Hamburg 2022
Flownative Beach - Neos Meetup Hamburg 2022Robert Lemke
 
GitOps with Flux - IPC Munich 2022
GitOps with Flux - IPC Munich 2022GitOps with Flux - IPC Munich 2022
GitOps with Flux - IPC Munich 2022Robert Lemke
 
OpenID Connect with Neos and Flow
OpenID Connect with Neos and FlowOpenID Connect with Neos and Flow
OpenID Connect with Neos and FlowRobert Lemke
 
Neos Conference 2019 Keynote
Neos Conference 2019 KeynoteNeos Conference 2019 Keynote
Neos Conference 2019 KeynoteRobert Lemke
 
A practical introduction to Kubernetes (IPC 2018)
A practical introduction to Kubernetes (IPC 2018)A practical introduction to Kubernetes (IPC 2018)
A practical introduction to Kubernetes (IPC 2018)Robert Lemke
 
Neos Conference 2018 Welcome Keynote
Neos Conference 2018 Welcome KeynoteNeos Conference 2018 Welcome Keynote
Neos Conference 2018 Welcome KeynoteRobert Lemke
 
A practical introduction to Event Sourcing and CQRS
A practical introduction to Event Sourcing and CQRSA practical introduction to Event Sourcing and CQRS
A practical introduction to Event Sourcing and CQRSRobert Lemke
 
Neos Conference 2017 Welcome Keynote
Neos Conference 2017 Welcome KeynoteNeos Conference 2017 Welcome Keynote
Neos Conference 2017 Welcome KeynoteRobert Lemke
 
IPC 2016: Content Strategy for Developers
IPC 2016: Content Strategy for DevelopersIPC 2016: Content Strategy for Developers
IPC 2016: Content Strategy for DevelopersRobert Lemke
 
Docker in Production - IPC 2016
Docker in Production - IPC 2016Docker in Production - IPC 2016
Docker in Production - IPC 2016Robert Lemke
 
Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)
Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)
Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)Robert Lemke
 
The Neos Brand (Inspiring Conference 2016)
The Neos Brand (Inspiring Conference 2016)The Neos Brand (Inspiring Conference 2016)
The Neos Brand (Inspiring Conference 2016)Robert Lemke
 
Neos - past, present, future (Inspiring Conference 2016)
Neos - past, present, future (Inspiring Conference 2016)Neos - past, present, future (Inspiring Conference 2016)
Neos - past, present, future (Inspiring Conference 2016)Robert Lemke
 
Meet Neos Nürnberg 2016: Ja ich will!
Meet Neos Nürnberg 2016: Ja ich will!Meet Neos Nürnberg 2016: Ja ich will!
Meet Neos Nürnberg 2016: Ja ich will!Robert Lemke
 
Meet Neos Nürnberg 2016: Hallo Neos!
Meet Neos Nürnberg 2016: Hallo Neos!Meet Neos Nürnberg 2016: Hallo Neos!
Meet Neos Nürnberg 2016: Hallo Neos!Robert Lemke
 
Turning Neos inside out / React.js HH
Turning Neos inside out / React.js HHTurning Neos inside out / React.js HH
Turning Neos inside out / React.js HHRobert Lemke
 
Docker in Production - IPC 15 München
Docker in Production - IPC 15 MünchenDocker in Production - IPC 15 München
Docker in Production - IPC 15 MünchenRobert Lemke
 

Mehr von Robert Lemke (20)

Neos Content Repository – Git for content
Neos Content Repository – Git for contentNeos Content Repository – Git for content
Neos Content Repository – Git for content
 
A General Purpose Docker Image for PHP
A General Purpose Docker Image for PHPA General Purpose Docker Image for PHP
A General Purpose Docker Image for PHP
 
Scaleable PHP Applications in Kubernetes
Scaleable PHP Applications in KubernetesScaleable PHP Applications in Kubernetes
Scaleable PHP Applications in Kubernetes
 
Flownative Beach - Neos Meetup Hamburg 2022
Flownative Beach - Neos Meetup Hamburg 2022Flownative Beach - Neos Meetup Hamburg 2022
Flownative Beach - Neos Meetup Hamburg 2022
 
GitOps with Flux - IPC Munich 2022
GitOps with Flux - IPC Munich 2022GitOps with Flux - IPC Munich 2022
GitOps with Flux - IPC Munich 2022
 
OpenID Connect with Neos and Flow
OpenID Connect with Neos and FlowOpenID Connect with Neos and Flow
OpenID Connect with Neos and Flow
 
Neos Conference 2019 Keynote
Neos Conference 2019 KeynoteNeos Conference 2019 Keynote
Neos Conference 2019 Keynote
 
A practical introduction to Kubernetes (IPC 2018)
A practical introduction to Kubernetes (IPC 2018)A practical introduction to Kubernetes (IPC 2018)
A practical introduction to Kubernetes (IPC 2018)
 
Neos Conference 2018 Welcome Keynote
Neos Conference 2018 Welcome KeynoteNeos Conference 2018 Welcome Keynote
Neos Conference 2018 Welcome Keynote
 
A practical introduction to Event Sourcing and CQRS
A practical introduction to Event Sourcing and CQRSA practical introduction to Event Sourcing and CQRS
A practical introduction to Event Sourcing and CQRS
 
Neos Conference 2017 Welcome Keynote
Neos Conference 2017 Welcome KeynoteNeos Conference 2017 Welcome Keynote
Neos Conference 2017 Welcome Keynote
 
IPC 2016: Content Strategy for Developers
IPC 2016: Content Strategy for DevelopersIPC 2016: Content Strategy for Developers
IPC 2016: Content Strategy for Developers
 
Docker in Production - IPC 2016
Docker in Production - IPC 2016Docker in Production - IPC 2016
Docker in Production - IPC 2016
 
Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)
Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)
Is this Open Source Thing Really Worth it? (IPC 2016 Berlin)
 
The Neos Brand (Inspiring Conference 2016)
The Neos Brand (Inspiring Conference 2016)The Neos Brand (Inspiring Conference 2016)
The Neos Brand (Inspiring Conference 2016)
 
Neos - past, present, future (Inspiring Conference 2016)
Neos - past, present, future (Inspiring Conference 2016)Neos - past, present, future (Inspiring Conference 2016)
Neos - past, present, future (Inspiring Conference 2016)
 
Meet Neos Nürnberg 2016: Ja ich will!
Meet Neos Nürnberg 2016: Ja ich will!Meet Neos Nürnberg 2016: Ja ich will!
Meet Neos Nürnberg 2016: Ja ich will!
 
Meet Neos Nürnberg 2016: Hallo Neos!
Meet Neos Nürnberg 2016: Hallo Neos!Meet Neos Nürnberg 2016: Hallo Neos!
Meet Neos Nürnberg 2016: Hallo Neos!
 
Turning Neos inside out / React.js HH
Turning Neos inside out / React.js HHTurning Neos inside out / React.js HH
Turning Neos inside out / React.js HH
 
Docker in Production - IPC 15 München
Docker in Production - IPC 15 MünchenDocker in Production - IPC 15 München
Docker in Production - IPC 15 München
 

Aspect-Oriented Programming and Depedency Injection

  • 1. Robert Lemke | TYPO3 Association AOP and Dependency Injection
  • 2. Overview About me, the flow and buzz ... Unit Testing Dependency Injection Aspect-Oriented Programming AOP and Dependency Injection
  • 3. 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 AOP and Dependency Injection
  • 4. About me HINT 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 AOP and Dependency Injection
  • 5. 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 AOP and Dependency Injection
  • 6. About the buzz AOP, DI, DDD, TDD, XP, ... ? YAGNI ? IMYLME ! AOP and Dependency Injection
  • 7. The Demo Package Demo AOP and Dependency Injection
  • 8.
  • 9. 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 AOP and Dependency Injection
  • 10. Unit Testing Dependencies Problem: Classes explicitly refer to other classes: AOP and Dependency Injection
  • 11. Unit Testing Dependencies Try to test this class: AOP and Dependency Injection
  • 12. 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 AOP and Dependency Injection
  • 13. 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 AOP and Dependency Injection
  • 14. 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 AOP and Dependency Injection
  • 15. Dependency Injection Constructor without Dependency Injection AOP and Dependency Injection
  • 16. Dependency Injection Component with Constructor Injection AOP and Dependency Injection
  • 17. Dependency Injection Component with Setter Injection AOP and Dependency Injection
  • 18. Dependency Injection Component Manager Manages the whole object lifecycle Provides so-called "IoC Container" Components: objects Components can be configured AOP and Dependency Injection
  • 19. 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 AOP and Dependency Injection
  • 20. 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 AOP and Dependency Injection
  • 21. 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" AOP and Dependency Injection
  • 22. Components Component scope AOP and Dependency Injection
  • 23. 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? AOP and Dependency Injection
  • 24. Components Creating Prototypes Solution A: Call getComponent() AOP and Dependency Injection
  • 25. Components Creating Prototypes Solution B: Call a factory method AOP and Dependency Injection
  • 26. 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 AOP and Dependency Injection
  • 27. Aspect Oriented Programming Cross-cutting concerns Presentation Domain Data source AOP and Dependency Injection
  • 28. Aspect Oriented Programming Cross-cutting concerns Presentation The concerns live here Domain Data source AOP and Dependency Injection
  • 29. Aspect Oriented Programming Cross-cutting concerns Some Domain Model Security CONCERNS Logging X-ING AOP and Dependency Injection
  • 30. Aspect Oriented Programming 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 AOP and Dependency Injection
  • 31. 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 AOP and Dependency Injection
  • 32. The AOP Hello World Classic Demo Demo AOP and Dependency Injection
  • 33.
  • 34. Aspect Oriented Programming Applications for AOP Logging Security Transactions Persistence Statistics In the Domain Layer AOP and Dependency Injection
  • 35. Aspect Oriented Programming Behind the Scenes Dynamic Proxy Classes Component Manager delivers the right implementation Only works if "new" is not used AOP and Dependency Injection
  • 36. More ... AOP and Dependency Injection
  • 37. More Where can I get FLOW3? From our Subversion repository: https://svn.typo3.org/FLOW3/Distribution/trunk/ AOP and Dependency Injection
  • 38. More ... DEV3 AOP and Dependency Injection
  • 39. More ... AOP Browser AOP and Dependency Injection
  • 40. More ... Known Issues FLOW3 (or rather PHP) currently causes Apache crashes - why ever ... Tests consume a lot of memory (> 400 MB) Access is comparably slow even in Production context (~ 3 req/s) and needs much memory (~ 20 MB) Many aspects are work in progress and neither optimized nor finished AOP and Dependency Injection
  • 41. Links FLOW3 Website http://flow3.typo3.org TYPO3 Forge http://forge.typo3.org T3CAST http://typo3.org/podcasts/robert AOP and Dependency Injection
  • 42. So long and thanks for the fish Questions AOP and Dependency Injection