Dependency Injection for Mere Humans
summary
Distinguishes service locator from dependency injection, proves DI by refactoring an order processor: extracts four concrete dependencies (repository, logger, time, mailer), converts static mailer to an injected instance, moves current time from constructor to method parameter and uses a null logger pattern; demonstrates Constructor injection, parameter injection and lazy wiring with a PSR-11 container (Pimple and a 140/280-character toy container), warns against using the container as a service locator.
AI-written summary · about
chapters (16)
- 0:00Dependency Injection intro
- 1:08Why DI matters
- 4:46Class-level dependencies
- 10:24Obscure dependencies
- 13:55Refactoring to dependency injection
- 15:21Constructor injection
- 18:57Setter injection options
- 25:24Optional dependencies
- 27:11Parameter injection
- 31:01Dependency inversion
- 38:06Refactoring step-by-step
- 42:47How DI containers work
- 49:29PSR-11 container
- 51:14FizzBuzz container example
- 53:45Pimple in Slim
- 56:18Summary
related talks
27mDemystifying Dependency Injection Containers
43mPerf and dependency injection — are you lazy enough?
02h 23mMastering Symfony 4's Dependency Injection
38mIOC container beyond constructor injection
49m"Deep Dive into Symfony's Dependency Injection Component"
41mFrom Helpers to Middleware
01h 00mDad, how are Service Containers born?
27mForgoing the Framework While Working with a Framework
