Compile- and Run-Time Dependency Injection
summary
Compares runtime dependency injection via abstract interfaces to compile-time dependency injection via templates using an alarm clock example wired to std::chrono and std::cout; introduces time fake and output fake so tests advance time instantly instead of waiting 10 minutes, making unit tests fast and verifiable. Runtime DI keeps swap-at-runtime and clear interface contracts but pays virtual-call overhead; compile-time DI removes virtual calls (useful in embedded hotspots) but requires concrete types at compile time. Demonstration runs on Compiler Explorer with 25 ms/10 ms demo values.
AI-written summary · about
chapters (9)
- 0:00Introduction
- 1:02Speaker background
- 3:28Talk overview
- 4:13Alarm clock example
- 6:48Naive implementation
- 10:20Runtime dependency injection
- 19:10Compile-time injection
- 26:03Pros and cons summary
- 28:33Code review and Q&A
related talks
01h 29mDependency Injection in C++ - A Practical Guide
01h 01mDependency Injection in C++ - A Practical Guide
05mConcept Driven Design with Dependency Injection
37mAdvanced multi-platform dependency injection
49mReaders vs Constructors: Dependency Injection showdown
01h 28mLaw of Demeter: A Practical Guide to Loose Coupling
56mDI Frameworks – some hidden pearls
30mThe Imposter’s Guide To Dependency Injection
