~/talk

How to Use C++ Dependency Injection to Write Maintainable Software

Talkat CppCon 2022 · 2022-09-11..09-16· [testing]
slides:none on file

Concrete rules for C++ dependency injection: prefer constructor or function parameters over setters, pass read‑only data as value or const reference and behaviors as std::function / std::function_ref or Concepts/abstract base classes, use factories to defer instantiation, avoid piping and forced lifetime choices, prefer references/unique_ptrs where ownership is clear, use aliasing constructor or holder pattern when factories must bundle lifetimes, and leverage testing with Google Test/Mock to inject mocks; expect tradeoffs in performance and header coupling.

AI-written summary · about

  1. 0:00Intro
  2. 1:00Dependency Injection
  3. 5:36How to pass dependencies around
  4. 13:17Data which is constant
  5. 14:29Data which might change
  6. 23:31Passing the dependencies
  7. 28:19References are Universal
  8. 34:11Factories
  9. 35:31Unique Point
  10. 41:58The Solution
  11. 44:56Advantages and Disadvantages
  12. 46:08Testability
  13. 47:20Recap
  14. 48:09Conclusion
  15. 48:37Questions
  16. 49:16Can it work
  17. 52:46Passing as a parameter
  18. 55:04Multiple functions
  19. 57:59Piping
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.