SlideShare una empresa de Scribd logo
1 de 47
October 2011




ZendDi
Who Am I?


    •Ralph Schindler (ralphschindler)
     Software Engineer on the Zend Framework team
      •At Zend for almost 4 years
      •Before that TippingPoint/3Com
    Programming PHP for 13+ years
    Live in New Orleans, LA.
      •Lived in Austin, Tx for 5 years

    My background with Di
      •I was part of the original roundtable 3yr ago @ zendcon
       –Fabien + Stephan + Myself
2
First Some Background




    •Background
     Di Definitions
     Some generic patterns




3
Dependency Injection


    •Subject matter expert: Martin Fowler
     not the only one, but has a nice take on it
    •http://martinfowler.com/articles/
     injection.html




4
Di vs. DiC

    •Di is a pattern
     This is non-negotiable
     DI is about Inversion Of Control (IoC)
       –sometimes not an easy concept to grasp for
        beginner and intermediate developers
    •DiC is a tool
     Subject to a developer’s or a group of
     developers requirements
     I.E.: no formal definition
      •as such, lots of frameworks provide this in some
       way shape or form
5
Important Fowler Quote


    •“Inversion of control is a common feature
     of frameworks, but it's something that
     comes at a price. It tends to be hard to
     understand and leads to problems when
     you are trying to debug. So on the whole I
     prefer to avoid it unless I need it. This isn't
     to say it's a bad thing, just that I think it
     needs to justify itself over the more
     straightforward alternative.”


6
Di: In a Nutshell


    •Obligatory:




7
Di’s Misguided Argument


    •Testing
     everyone quotes this as the argument for
     dependency injection
     •correct for silo’d development
     •if you are the only consumer of your code
    too much emphasis here




8
The Better Di Argument



      •Makes it easy for developers to swap
       out implementation
      •Paddy Brady:
       ... “it helps ensure source code can be
        maintained in a highly decoupled state.
        Which make it easier to subclass the Zend
        Framework to death, and modify it’s
        components before use.”


9
Di Identified Types


     •Constructor
      Favored by PicoContainer derivatives
     •Setter
      Favored by Spring Container derivatives




10
Di 3rd Injection Type


     •Interface Injection
      but first as segue ...




11
What is an Interface


     •A contract that forces subtypes to conform
      to particular method signatures so that
      objects can exhibit particular behaviors




12
Interfaces


     •Interface best practices
      No constructors
      No static methods
     •Why? Because interfaces are about
      “alternate implementations”
     •PHP allows statics and constructors in
      interfaces
      for better or worse



13
Interfaces explained


     •A better way to think about it
      Interfaces are about contracts in behavior
      between developers
      Point in case, search for “friends” in this
      page:
       •http://martinfowler.com/articles/injection.html




14
Interfaces in practice




15
Back To Interface Injection


     •First and foremost: a communication tool
     •Form of setter injection (or, injection via
      method)
     •The dependency is implied by the
      interface and the injection point is forced
      by the interface
      Always part of the type’s hierarchy
     •Rely’s on a managing/consuming object/
      framework for execution - or a really strict
      developer
16
Interface Injection Example




17
Interface Injection Pattern


     •Not formal / it is semi-de-facto
     •Interface injection is tricker to understand
      without context
     •(Semi) Well known pattern at play
      the “Aware” interface name




18
Interface Injection Downside


     •At the application layer, it leads to having
      to write and consume lots of interfaces to
      get things sorted out




19
Interface Injection Downside




20
Constructor vs. Setter Injection


     •Constructor
      Pro: object in ready state
      Con: there is a param per dependency
       •too busy of an object? or just right?
     Con: dependencies are not polymorphic
     Pro/Con: dependencies can (not?) be
     swappable after instantiation
     Pro: object declares complexity up front
     Con: can lead to cyclical dependencies

21
Constructor vs. Setter Injection


     •Constructor continued:
       •Constructors are not subject to Liskov Substitution
        Principle (Ctor is not part of the type in question)
        –In other languages ctors are static




22
Constructor vs. Setter Injection


     •Setter
      Pro: clear injection points for each
      dependency
      Con: consumer has to be very honest about
      injecting all dependencies
      Con: construct is not up front about required
      dependencies
       •hard to distinguish optional vs. required
        dependencies
        –is this really such a thing?

23
Misconceptions?


     •(SL) Service Locators !== (DiC) Dependency
      Injection Containers
     •But DiC == SL
      DiC’s can be the foundation of consumed for
       service location




24
Typical Dependency Injection Graph




25
Service Locator


     •It is understood that services to be locator
      aware
     •Pros:
      not all code paths in the consuming object
       might use all the dependencies
       •Example: controller
     •Cons:
      service locator becomes the dependency



26
Service Locator Graph




27
•ZendDi




28
Why Di For Zend


     •Considering a DiC is a first world problem
      for developers
     •Why did we create this component?
      You’re afraid of “new”?
      You asked for it
     •Having a DI Container that tries to
      understand your code makes you code
      better


29
Questions Raised


     •But is it really possible to force developers
      to write better code?
     •How do we look at a use case and tell if
      the DiC is falling short, or the developer is
      writing bad code?
      There is a fine line




30
DiCs Out There - Not PHP


     •Java
      Spring, PicoContainer
     •.net
      Spring.Net, StructureMap, Unity, Castle’s
      Windsor




31
ZendDi perspective


     •we support both:
      "This issue has led to a lot of debate between
      the various teams who provide dependency
      injectors as part of their frameworks. However
      it seems that most people who build these
      frameworks have realized that it's important to
      support both mechanisms, even if there's a
      preference for one of them."
       •-Martin Fowler


32
Developing ZendDi




     •Development of ZendDi




33
Goals


     •Find a way to produce a DiC that works for
      PHP developers and all their “tendencies”
      very hard to identify
     •Performant - as best as possible
      we have no persistent memory
     •The same or less code required than
      actually just writing the code in the first
      place


34
A Note on DI and Performance


     •Di is just code, it is a performant as not
      practicing Di
      so long as you’re still using the same number
       of dependencies/objects
     •DiC is not performance friendly!
      Front loading workflow, structural needs
      NOT Hello World friendly!




35
ZendDi Parts




     •Two main components
      Definition
      Instance Configuration
       •Runtime concerns




36
ZendDi Definition


     •Goals
      Explain what the code looks like, what it
      expects
      Identify which classes have dependencies
      Identify injection points
      Names for all the moving parts




37
ZendDi Definition


     •Instantiation:
      Constructor (new keyword)
      Callback (factory pattern)
       •Via object factory
       •Via static factory method




38
ZendDi Definition


     •From a very fundamental level, injection
      always comes in the two forms
      Via constructor params
      Via method injection
     •We (currently) do not support public
      property setting




39
ZendDi Definition


     •Naming dependency/configuration entry
      points
      Is an object expected? Is there a type hint?
       •Where does it originate from?
     Is a scalar expected? Is it optional?




40
ZendDi Configuration


     •Goals
      Encapsulate runtime data required to wire
      instances
       •Could be environment specific (dev. different than
        production)
     Be able to identify which objects fulfill a
      dependency (preferred types)




41
Definition & Configuration


     •A better understanding:
      Definitions can be shipped with your code,
      they are independent of how they are used
      Configuration is what is expected of anyone
      consuming ZendDi




42
Building Definitions


     •At Runtime (on-demand)
      Great for development, terrible for
      production, esp. with annotations turned on
     •Compiler (Reflection+Scanner)
      (yesterday’s talk on ZendCode)
      Compiled into an array; used with
      ArrayDefinition
     •By-Hand
      ClassDefinition
      BuilderDefinition
43
Demo Time


     •Live Demo Time

     •Code:
      https://github.com/ralphschindler/Zend_DI-
      Examples
      Uses ZF2 Beta Phars




44
Other Containers


     •Yadif (beberlei)
     •Pimple (Fabien Potencier)
     •Symfony Di Container for 5.3
     •PicoContainer
      more than 5 years old




45
ZendDi Todo


     •Further divorce the Service Locator /
      Dependency Injection Container
     •Service locators can be defined by
      callbacks (closures)




46
Thanks!




     •Questions, Concerns?
     •Thanks!




47

Más contenido relacionado

La actualidad más candente

A Lap Around Visual Studio 11
A Lap Around Visual Studio 11A Lap Around Visual Studio 11
A Lap Around Visual Studio 11Chad Green
 
Advanced IDE functionality in modern language workbenches
Advanced IDE functionality in modern language workbenchesAdvanced IDE functionality in modern language workbenches
Advanced IDE functionality in modern language workbenchesVaclav Pech
 
Design for Testability
Design for Testability Design for Testability
Design for Testability Pawel Kalbrun
 
Don't let your tests slow you down
Don't let your tests slow you downDon't let your tests slow you down
Don't let your tests slow you downDaniel Irvine
 
Confoo 2011 - Advanced OO Patterns
Confoo 2011 - Advanced OO PatternsConfoo 2011 - Advanced OO Patterns
Confoo 2011 - Advanced OO PatternsBachkoutou Toutou
 
Concepts of JetBrains MPS
Concepts of JetBrains MPSConcepts of JetBrains MPS
Concepts of JetBrains MPSVaclav Pech
 
Top 50 .NET Interview Questions and Answers 2019 | Edureka
Top 50 .NET Interview Questions and Answers 2019 | EdurekaTop 50 .NET Interview Questions and Answers 2019 | Edureka
Top 50 .NET Interview Questions and Answers 2019 | EdurekaEdureka!
 
Refactoring for Software Design Smells
Refactoring for Software Design SmellsRefactoring for Software Design Smells
Refactoring for Software Design SmellsGanesh Samarthyam
 
How To Become A Good C# Programmer
How To Become A Good C# ProgrammerHow To Become A Good C# Programmer
How To Become A Good C# ProgrammerLearnItFirst.com
 
C# Interview Questions | Edureka
C# Interview Questions | EdurekaC# Interview Questions | Edureka
C# Interview Questions | EdurekaEdureka!
 
Scrum is not enough - being a successful agile engineer
Scrum is not enough - being a successful agile engineerScrum is not enough - being a successful agile engineer
Scrum is not enough - being a successful agile engineerAnton Keks
 
Prefer Code to Comments
Prefer Code to CommentsPrefer Code to Comments
Prefer Code to CommentsKevlin Henney
 

La actualidad más candente (14)

A Lap Around Visual Studio 11
A Lap Around Visual Studio 11A Lap Around Visual Studio 11
A Lap Around Visual Studio 11
 
Advanced IDE functionality in modern language workbenches
Advanced IDE functionality in modern language workbenchesAdvanced IDE functionality in modern language workbenches
Advanced IDE functionality in modern language workbenches
 
Design for Testability
Design for Testability Design for Testability
Design for Testability
 
Don't let your tests slow you down
Don't let your tests slow you downDon't let your tests slow you down
Don't let your tests slow you down
 
Confoo 2011 - Advanced OO Patterns
Confoo 2011 - Advanced OO PatternsConfoo 2011 - Advanced OO Patterns
Confoo 2011 - Advanced OO Patterns
 
Concepts of JetBrains MPS
Concepts of JetBrains MPSConcepts of JetBrains MPS
Concepts of JetBrains MPS
 
Top 50 .NET Interview Questions and Answers 2019 | Edureka
Top 50 .NET Interview Questions and Answers 2019 | EdurekaTop 50 .NET Interview Questions and Answers 2019 | Edureka
Top 50 .NET Interview Questions and Answers 2019 | Edureka
 
Refactoring for Software Design Smells
Refactoring for Software Design SmellsRefactoring for Software Design Smells
Refactoring for Software Design Smells
 
How To Become A Good C# Programmer
How To Become A Good C# ProgrammerHow To Become A Good C# Programmer
How To Become A Good C# Programmer
 
C# Interview Questions | Edureka
C# Interview Questions | EdurekaC# Interview Questions | Edureka
C# Interview Questions | Edureka
 
Scrum is not enough - being a successful agile engineer
Scrum is not enough - being a successful agile engineerScrum is not enough - being a successful agile engineer
Scrum is not enough - being a successful agile engineer
 
Prefer Code to Comments
Prefer Code to CommentsPrefer Code to Comments
Prefer Code to Comments
 
Inside Requirements
Inside RequirementsInside Requirements
Inside Requirements
 
Sorted
SortedSorted
Sorted
 

Destacado

Virtual staffing process
Virtual staffing processVirtual staffing process
Virtual staffing processAndrew Watson
 
Zend_Tool In ZF 1.8 Webinar
Zend_Tool In ZF 1.8 WebinarZend_Tool In ZF 1.8 Webinar
Zend_Tool In ZF 1.8 WebinarRalph Schindler
 
Zend Framework 1.8 Features Webinar
Zend Framework 1.8 Features WebinarZend Framework 1.8 Features Webinar
Zend Framework 1.8 Features WebinarRalph Schindler
 
Software Engineering In PHP
Software Engineering In PHPSoftware Engineering In PHP
Software Engineering In PHPRalph Schindler
 
Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2Ralph Schindler
 

Destacado (8)

Virtual staffing process
Virtual staffing processVirtual staffing process
Virtual staffing process
 
Zend_Tool In ZF 1.8 Webinar
Zend_Tool In ZF 1.8 WebinarZend_Tool In ZF 1.8 Webinar
Zend_Tool In ZF 1.8 Webinar
 
484 Days of PHP 5.3
484 Days of PHP 5.3484 Days of PHP 5.3
484 Days of PHP 5.3
 
Zend Code in ZF 2.0
Zend Code in ZF 2.0Zend Code in ZF 2.0
Zend Code in ZF 2.0
 
Zend Framework 1.8 Features Webinar
Zend Framework 1.8 Features WebinarZend Framework 1.8 Features Webinar
Zend Framework 1.8 Features Webinar
 
Software Engineering In PHP
Software Engineering In PHPSoftware Engineering In PHP
Software Engineering In PHP
 
Modeling best practices
Modeling best practicesModeling best practices
Modeling best practices
 
Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2
 

Similar a Zend Di in ZF 2.0

Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®Hannes Lowette
 
Devconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developedDevconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developedAlexander Makarov
 
Stephen Pope - Sitecore on the bleeding edge
Stephen Pope - Sitecore on the bleeding edgeStephen Pope - Sitecore on the bleeding edge
Stephen Pope - Sitecore on the bleeding edgeNordicSitecoreConference
 
From silex to symfony and viceversa
From silex to symfony and viceversaFrom silex to symfony and viceversa
From silex to symfony and viceversaRonny López
 
Slides for Houston iPhone Developers' Meetup (April 2012)
Slides for Houston iPhone Developers' Meetup (April 2012)Slides for Houston iPhone Developers' Meetup (April 2012)
Slides for Houston iPhone Developers' Meetup (April 2012)lqi
 
Writing Testable Code in SharePoint
Writing Testable Code in SharePointWriting Testable Code in SharePoint
Writing Testable Code in SharePointTim McCarthy
 
Code refactoring
Code refactoringCode refactoring
Code refactoringLalit Kale
 
Architectural Decisions: Smoothly and Consistently
Architectural Decisions: Smoothly and ConsistentlyArchitectural Decisions: Smoothly and Consistently
Architectural Decisions: Smoothly and ConsistentlyComsysto Reply GmbH
 
Architectural Decisions: Smoothly and Consistently
Architectural Decisions: Smoothly and ConsistentlyArchitectural Decisions: Smoothly and Consistently
Architectural Decisions: Smoothly and ConsistentlyComsysto Reply GmbH
 
Schibsted Spain - Day 1 - DDD Course
Schibsted Spain - Day 1 - DDD CourseSchibsted Spain - Day 1 - DDD Course
Schibsted Spain - Day 1 - DDD CourseKevin Mas Ruiz
 
Extending ZF & Extending With ZF
Extending ZF & Extending With ZFExtending ZF & Extending With ZF
Extending ZF & Extending With ZFRalph Schindler
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Codersebbe
 
DIC To The Limit – deSymfonyDay, Barcelona 2014
DIC To The Limit – deSymfonyDay, Barcelona 2014DIC To The Limit – deSymfonyDay, Barcelona 2014
DIC To The Limit – deSymfonyDay, Barcelona 2014Ronny López
 
Writing Services with ZF2
Writing Services with ZF2Writing Services with ZF2
Writing Services with ZF2Mike Willbanks
 
Unit Test for ZF SlideShare Component
Unit Test for ZF SlideShare ComponentUnit Test for ZF SlideShare Component
Unit Test for ZF SlideShare ComponentKaiuwe
 
Unit Test for ZF SlideShare Component
Unit Test for ZF SlideShare ComponentUnit Test for ZF SlideShare Component
Unit Test for ZF SlideShare ComponentKaiuwe
 

Similar a Zend Di in ZF 2.0 (20)

Clean Code V2
Clean Code V2Clean Code V2
Clean Code V2
 
Code detox
Code detoxCode detox
Code detox
 
Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®
 
Devconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developedDevconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developed
 
Stephen Pope - Sitecore on the bleeding edge
Stephen Pope - Sitecore on the bleeding edgeStephen Pope - Sitecore on the bleeding edge
Stephen Pope - Sitecore on the bleeding edge
 
From silex to symfony and viceversa
From silex to symfony and viceversaFrom silex to symfony and viceversa
From silex to symfony and viceversa
 
Slides for Houston iPhone Developers' Meetup (April 2012)
Slides for Houston iPhone Developers' Meetup (April 2012)Slides for Houston iPhone Developers' Meetup (April 2012)
Slides for Houston iPhone Developers' Meetup (April 2012)
 
The Architect Way
The Architect WayThe Architect Way
The Architect Way
 
Writing Testable Code in SharePoint
Writing Testable Code in SharePointWriting Testable Code in SharePoint
Writing Testable Code in SharePoint
 
Code refactoring
Code refactoringCode refactoring
Code refactoring
 
Architectural Decisions: Smoothly and Consistently
Architectural Decisions: Smoothly and ConsistentlyArchitectural Decisions: Smoothly and Consistently
Architectural Decisions: Smoothly and Consistently
 
Architectural Decisions: Smoothly and Consistently
Architectural Decisions: Smoothly and ConsistentlyArchitectural Decisions: Smoothly and Consistently
Architectural Decisions: Smoothly and Consistently
 
Schibsted Spain - Day 1 - DDD Course
Schibsted Spain - Day 1 - DDD CourseSchibsted Spain - Day 1 - DDD Course
Schibsted Spain - Day 1 - DDD Course
 
Extending ZF & Extending With ZF
Extending ZF & Extending With ZFExtending ZF & Extending With ZF
Extending ZF & Extending With ZF
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
 
From 1 to 100
From 1 to 100From 1 to 100
From 1 to 100
 
DIC To The Limit – deSymfonyDay, Barcelona 2014
DIC To The Limit – deSymfonyDay, Barcelona 2014DIC To The Limit – deSymfonyDay, Barcelona 2014
DIC To The Limit – deSymfonyDay, Barcelona 2014
 
Writing Services with ZF2
Writing Services with ZF2Writing Services with ZF2
Writing Services with ZF2
 
Unit Test for ZF SlideShare Component
Unit Test for ZF SlideShare ComponentUnit Test for ZF SlideShare Component
Unit Test for ZF SlideShare Component
 
Unit Test for ZF SlideShare Component
Unit Test for ZF SlideShare ComponentUnit Test for ZF SlideShare Component
Unit Test for ZF SlideShare Component
 

Último

Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 

Último (20)

Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 

Zend Di in ZF 2.0

  • 2. Who Am I? •Ralph Schindler (ralphschindler) Software Engineer on the Zend Framework team •At Zend for almost 4 years •Before that TippingPoint/3Com Programming PHP for 13+ years Live in New Orleans, LA. •Lived in Austin, Tx for 5 years My background with Di •I was part of the original roundtable 3yr ago @ zendcon –Fabien + Stephan + Myself 2
  • 3. First Some Background •Background Di Definitions Some generic patterns 3
  • 4. Dependency Injection •Subject matter expert: Martin Fowler not the only one, but has a nice take on it •http://martinfowler.com/articles/ injection.html 4
  • 5. Di vs. DiC •Di is a pattern This is non-negotiable DI is about Inversion Of Control (IoC) –sometimes not an easy concept to grasp for beginner and intermediate developers •DiC is a tool Subject to a developer’s or a group of developers requirements I.E.: no formal definition •as such, lots of frameworks provide this in some way shape or form 5
  • 6. Important Fowler Quote •“Inversion of control is a common feature of frameworks, but it's something that comes at a price. It tends to be hard to understand and leads to problems when you are trying to debug. So on the whole I prefer to avoid it unless I need it. This isn't to say it's a bad thing, just that I think it needs to justify itself over the more straightforward alternative.” 6
  • 7. Di: In a Nutshell •Obligatory: 7
  • 8. Di’s Misguided Argument •Testing everyone quotes this as the argument for dependency injection •correct for silo’d development •if you are the only consumer of your code too much emphasis here 8
  • 9. The Better Di Argument •Makes it easy for developers to swap out implementation •Paddy Brady: ... “it helps ensure source code can be maintained in a highly decoupled state. Which make it easier to subclass the Zend Framework to death, and modify it’s components before use.” 9
  • 10. Di Identified Types •Constructor Favored by PicoContainer derivatives •Setter Favored by Spring Container derivatives 10
  • 11. Di 3rd Injection Type •Interface Injection but first as segue ... 11
  • 12. What is an Interface •A contract that forces subtypes to conform to particular method signatures so that objects can exhibit particular behaviors 12
  • 13. Interfaces •Interface best practices No constructors No static methods •Why? Because interfaces are about “alternate implementations” •PHP allows statics and constructors in interfaces for better or worse 13
  • 14. Interfaces explained •A better way to think about it Interfaces are about contracts in behavior between developers Point in case, search for “friends” in this page: •http://martinfowler.com/articles/injection.html 14
  • 16. Back To Interface Injection •First and foremost: a communication tool •Form of setter injection (or, injection via method) •The dependency is implied by the interface and the injection point is forced by the interface Always part of the type’s hierarchy •Rely’s on a managing/consuming object/ framework for execution - or a really strict developer 16
  • 18. Interface Injection Pattern •Not formal / it is semi-de-facto •Interface injection is tricker to understand without context •(Semi) Well known pattern at play the “Aware” interface name 18
  • 19. Interface Injection Downside •At the application layer, it leads to having to write and consume lots of interfaces to get things sorted out 19
  • 21. Constructor vs. Setter Injection •Constructor Pro: object in ready state Con: there is a param per dependency •too busy of an object? or just right? Con: dependencies are not polymorphic Pro/Con: dependencies can (not?) be swappable after instantiation Pro: object declares complexity up front Con: can lead to cyclical dependencies 21
  • 22. Constructor vs. Setter Injection •Constructor continued: •Constructors are not subject to Liskov Substitution Principle (Ctor is not part of the type in question) –In other languages ctors are static 22
  • 23. Constructor vs. Setter Injection •Setter Pro: clear injection points for each dependency Con: consumer has to be very honest about injecting all dependencies Con: construct is not up front about required dependencies •hard to distinguish optional vs. required dependencies –is this really such a thing? 23
  • 24. Misconceptions? •(SL) Service Locators !== (DiC) Dependency Injection Containers •But DiC == SL DiC’s can be the foundation of consumed for service location 24
  • 26. Service Locator •It is understood that services to be locator aware •Pros: not all code paths in the consuming object might use all the dependencies •Example: controller •Cons: service locator becomes the dependency 26
  • 29. Why Di For Zend •Considering a DiC is a first world problem for developers •Why did we create this component? You’re afraid of “new”? You asked for it •Having a DI Container that tries to understand your code makes you code better 29
  • 30. Questions Raised •But is it really possible to force developers to write better code? •How do we look at a use case and tell if the DiC is falling short, or the developer is writing bad code? There is a fine line 30
  • 31. DiCs Out There - Not PHP •Java Spring, PicoContainer •.net Spring.Net, StructureMap, Unity, Castle’s Windsor 31
  • 32. ZendDi perspective •we support both: "This issue has led to a lot of debate between the various teams who provide dependency injectors as part of their frameworks. However it seems that most people who build these frameworks have realized that it's important to support both mechanisms, even if there's a preference for one of them." •-Martin Fowler 32
  • 33. Developing ZendDi •Development of ZendDi 33
  • 34. Goals •Find a way to produce a DiC that works for PHP developers and all their “tendencies” very hard to identify •Performant - as best as possible we have no persistent memory •The same or less code required than actually just writing the code in the first place 34
  • 35. A Note on DI and Performance •Di is just code, it is a performant as not practicing Di so long as you’re still using the same number of dependencies/objects •DiC is not performance friendly! Front loading workflow, structural needs NOT Hello World friendly! 35
  • 36. ZendDi Parts •Two main components Definition Instance Configuration •Runtime concerns 36
  • 37. ZendDi Definition •Goals Explain what the code looks like, what it expects Identify which classes have dependencies Identify injection points Names for all the moving parts 37
  • 38. ZendDi Definition •Instantiation: Constructor (new keyword) Callback (factory pattern) •Via object factory •Via static factory method 38
  • 39. ZendDi Definition •From a very fundamental level, injection always comes in the two forms Via constructor params Via method injection •We (currently) do not support public property setting 39
  • 40. ZendDi Definition •Naming dependency/configuration entry points Is an object expected? Is there a type hint? •Where does it originate from? Is a scalar expected? Is it optional? 40
  • 41. ZendDi Configuration •Goals Encapsulate runtime data required to wire instances •Could be environment specific (dev. different than production) Be able to identify which objects fulfill a dependency (preferred types) 41
  • 42. Definition & Configuration •A better understanding: Definitions can be shipped with your code, they are independent of how they are used Configuration is what is expected of anyone consuming ZendDi 42
  • 43. Building Definitions •At Runtime (on-demand) Great for development, terrible for production, esp. with annotations turned on •Compiler (Reflection+Scanner) (yesterday’s talk on ZendCode) Compiled into an array; used with ArrayDefinition •By-Hand ClassDefinition BuilderDefinition 43
  • 44. Demo Time •Live Demo Time •Code: https://github.com/ralphschindler/Zend_DI- Examples Uses ZF2 Beta Phars 44
  • 45. Other Containers •Yadif (beberlei) •Pimple (Fabien Potencier) •Symfony Di Container for 5.3 •PicoContainer more than 5 years old 45
  • 46. ZendDi Todo •Further divorce the Service Locator / Dependency Injection Container •Service locators can be defined by callbacks (closures) 46
  • 47. Thanks! •Questions, Concerns? •Thanks! 47

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. Is he talking about the practice or the container?\n
  7. \n
  8. \n
  9. \n
  10. \n
  11. How many of you use interfaces currently in your code in your orgnaization\n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. point in case on next slide:\n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n