DI, IoC, & You

Dependency Injection, Inversion of Control, and You

October 17, 2023

Outline

  1. Inversion of Control
  2. Dependency Injection
  3. django-di

What is Inversion of Control?

The idea that a library calls your code instead of you calling a library (framework).

Don't call us, we'll call you (Hollywood's Law)

What is Inversion of Control?

Instead of

your code => library

with IoC

your code <= library (inverted)

Examples of Inversion of Control

  • Tkinter
  • unittest (setUp, tearDown, ...)
  • Django views (called by Django framework)

What is Dependency Injection?

An IoC technique for separating construction from use.

We pass a class its dependencies instead of creating them within the class.

$10 word for a 5𝇍 concept

What are some benefits of DI?

  • Decreased coupling
  • Testability
  • Composability ("has a", not "is a")

Auto Dependency Injection

Taking things a step further with DI Containers

Summary

Zupah kewl summary

Questions?

Thank you all for coming! 👋

References

Show `ioc*.py` examples after this slide