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="maile...
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.n...
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Introduction to rg\injection
Upcoming SlideShare
Loading in …5
×

Introduction to rg\injection

5,312 views

Published on

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

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,312
On SlideShare
0
From Embeds
0
Number of Embeds
76
Actions
Shares
0
Downloads
16
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Introduction to rg\injection

  1. rginjection Bastian Hofmann
  2. Questions? Ask!
  3. Dependency Inversion
  4. http://www.doolwind.com/blog/solid-principles-for-game-developers/
  5. Dependencies
  6. Dependency Injection
  7. Constructor
  8. Setter
  9. Method argument
  10. Constructing classes
  11. Make it easier with factories
  12. Dependency Injection Container
  13. What‘s out there?
  14. <?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>
  15. rginjection inspired by google-guice http://code.google.com/p/google-guice/
  16. Creating an instance of a class
  17. Automatic creation of dependencies through Typehints
  18. @inject
  19. What classes can be injected?
  20. No constructor
  21. Constructor without arguments
  22. Constructor with arguments that have default values
  23. Injectable constructor
  24. By the way: Property Injection
  25. Singletons with public static getInstance method following the same rules
  26. STOP: Don‘t use Singeltons
  27. Singletons are evil!
  28. Let the DIC take care of instances
  29. @singleton
  30. By the way...
  31. Passing additional, fixed values to instance
  32. What about testing
  33. Only test the class, not the dependencies
  34. Mocking
  35. Working with Interfaces
  36. Why interfaces?
  37. But we can not create an instance of an Interface!
  38. @implementedBy
  39. Mocking an interface
  40. Named @implementedBy
  41. What‘s that for?
  42. Providers
  43. @providedBy
  44. Method invocation at DIC
  45. Same rules
  46. And if you don‘t like annotations...... or want to integrate 3rd party code
  47. Integrate it into your framework
  48. Great! So, how does it work internally?
  49. Development: Reflection
  50. Production: Generated Factory Classes
  51. DEMO
  52. Available? very soon
  53. h"p://twi"er.com/Bas2anHofmannh"ps://profiles.google.com/bashofmannh"p://lanyrd.com/people/Bas2anHofmann/h"p://slideshare.net/bashofmannmail@bas2anhofmann.de

×