Introduction to rg\injection
Upcoming SlideShare
Loading in...5
×
 

Introduction to rg\injection

on

  • 2,705 views

Presentation about rg\injection, a PHP dependency injection container which is inspired by google guice.

Presentation about rg\injection, a PHP dependency injection container which is inspired by google guice.

Statistics

Views

Total Views
2,705
Views on SlideShare
2,680
Embed Views
25

Actions

Likes
1
Downloads
14
Comments
0

6 Embeds 25

http://a0.twimg.com 8
http://lanyrd.com 8
http://coderwall.com 5
https://si0.twimg.com 2
http://www.mefeedia.com 1
https://twitter.com 1

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Introduction to rg\injection Introduction to rg\injection Presentation Transcript

  • rginjection Bastian Hofmann
  • Questions? Ask!
  • Dependency Inversion
  • http://www.doolwind.com/blog/solid-principles-for-game-developers/
  • Dependencies
  • Dependency Injection
  • Constructor
  • Setter
  • Method argument
  • Constructing classes
  • Make it easier with factories
  • Dependency Injection Container
  • What‘s out there?
  • <?xml version="1.0" ?> <container xmlns="http://symfony-project.org/2.0/container"> <parameters> <parameter key="mailer.username">foo</parameter> <parameter key="mailer.password">bar</parameter> <parameter key="mailer.class">Zend_Mail</parameter> </parameters> <services> <service id="mail.transport"class="Zend_Mail_Transport_Smtp" shared="false"> <argument>smtp.gmail.com</argument> <argument type="collection"> <argument key="auth">login</argument> <argument key="username">%mailer.username%</argument> <argument key="password">%mailer.password%</argument> <argument key="ssl">ssl</argument> <argument key="port">465</argument> </argument> </service> <service id="mailer" class="%mailer.class%"> <call method="setDefaultTransport"> <argument type="service" id="mail.transport" /> </call> </service> </services></container>
  • rginjection inspired by google-guice http://code.google.com/p/google-guice/
  • Creating an instance of a class
  • Automatic creation of dependencies through Typehints
  • @inject
  • What classes can be injected?
  • No constructor
  • Constructor without arguments
  • Constructor with arguments that have default values
  • Injectable constructor
  • By the way: Property Injection
  • Singletons with public static getInstance method following the same rules
  • STOP: Don‘t use Singeltons
  • Singletons are evil!
  • Let the DIC take care of instances
  • @singleton
  • By the way...
  • Passing additional, fixed values to instance
  • What about testing
  • Only test the class, not the dependencies
  • Mocking
  • Working with Interfaces
  • Why interfaces?
  • But we can not create an instance of an Interface!
  • @implementedBy
  • Mocking an interface
  • Named @implementedBy
  • What‘s that for?
  • Providers
  • @providedBy
  • Method invocation at DIC
  • Same rules
  • And if you don‘t like annotations...... or want to integrate 3rd party code
  • Integrate it into your framework
  • Great! So, how does it work internally?
  • Development: Reflection
  • Production: Generated Factory Classes
  • DEMO
  • Available? very soon
  • h"p://twi"er.com/Bas2anHofmannh"ps://profiles.google.com/bashofmannh"p://lanyrd.com/people/Bas2anHofmann/h"p://slideshare.net/bashofmannmail@bas2anhofmann.de