Dependency Injection

“It's terrible to have to depend on someone else.”

— Jeff Lindsay, Dearly Devoted Dexter

Stig Lindqvist / @stojg

“I'll talk for a while and hope sufficiently to provoke and inflame opinion that there'll be an outburst of chair-throwing at the end.”

— Douglas Adams

What GoF have to say about this

Design Patterns: Elements of Reusable Object-Oriented Software - 1994



“Dependency injection is a software design pattern that allows the removal of hard-coded dependencies and makes it possible to change them, whether at run-time or compile-time.”


“Put simply, a Service is any PHP object that performs some sort of "global" task. It's a purposefully-generic name used in computer science to describe an object that's created for a specific purpose (e.g. delivering emails).”

— Symphony Framework on DI

Scope creep

  • Staging - send to tester instead
  • Production - must use SMTP
“Easy, I'll just add more if / else in the controller.”
  • Open source?
“Everything should be made as simple as possible, but not simpler.” - Albert Einstein

Yeah, okey..

Full contact karate

In object-oriented computer programming, a factory is an object for creating other objects.
… or let's have a cup of java.

Anti Patterns

Don't be clever

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian Kernighan

Thank you!

You are now free to start hurling the chairs around!

Resources | @stojg