Dependency injection is your friend
summary
Argues that explicit dependency injection wins in Python by enforcing interfaces, reducing brittle tests from monkeypatching, and removing tangled construction order. Shows a small Python DI library with constructor injection, an application context that registers provider methods, a lazy singleton scope and provider-decorated factory functions. Demonstrates wiring a DB driver → user repository → user service, keeps configuration declarative so imports and instantiation order vanish, and reports the library works for real projects while avoiding setter/field injection and decorator-based clutter.
AI-written summary · about
chapters (18)
- 0:00Introduction
- 1:37Dependency injection and SOLID
- 3:04Misconceptions about DI
- 6:00Programming to interfaces
- 9:15Constructor injection and encapsulation
- 12:30Interfaces vs implementation
- 15:02Redefining encapsulation
- 17:14Component design and wiring
- 18:58Simplifying code with DI
- 21:05Testing pitfalls and refactoring
- 23:57Constructor injection benefits
- 25:26Project showcase and feedback
- 26:30Encapsulation and abstraction
- 33:50Configuration and dynamic building
- 37:48IOC containers and resolution
- 40:12Declarative configuration
- 41:57Application context and retrieval
- 42:19Python DI libraries comparison
related talks
05mDependency Injection
01h 29mDependency Injection in C++ - A Practical Guide
19mFang: Pythonic dependency injection
46mSlaying Sacred Cows: Deconstructing Dependency Injection
45mTesting via fake injection in Django
40mFundamentals of Dependency Injection
49mReaders vs Constructors: Dependency Injection showdown
54mDependency Injection revisited
