Gail  Wilderman

Gail Wilderman


Dependency INVERSION VS Dependency INJECTION in Python

What’s the difference between dependency inversion and dependency injection? Dependency injection is a design pattern that splits creation of objects from their usage. Dependency inversion is a design principle that promotes using abstract classes and interfaces to better separate code. Watch this video to see a few practical examples in Python, and how these concepts help you write nice code that’s easy to test.

✅ Write cleaner code with Sourcery:

My software development setup:
💻 Apple M1 Macbook Air:
⌨ Keychron K2 mechanical keyboard (awesome typing experience):

My camera gear:
📷 Sony A7C -
🎙 Rode Wireless GO -
🎙 Electrovoice RE20 -
🎙 Sennheiser MKH416 P48 -
🎚 Sound Devices Mix-Pre 3 II -
💡 GVM RGB LED light -
💡 GVM 100W light with lantern softbox -

☕If you want to support this channel, you can buy me a coffee here:

A few interesting links to articles and books:

The code I worked on in this example is available here:

👍 If you enjoyed this content, give this video a like. If you want to watch more of my upcoming videos, consider subscribing to my channel!

💬 Join my Discord server here:


🔖 Chapters:
0:00 Intro
0:20 What is a dependency?
1:10 Dependency injection
1:36 Dependency inversion
2:03 Example code
3:22 Example unit tests
5:32 Issues with testing
6:37 Applying dependency injection
8:35 Writing the unit tests
11:20 Applying dependency inversion
12:51 Coverage reports and abstract classes
14:16 The power of dependency inversion
14:49 Adding another authorizer
15:44 Adding tests for the Robot authorizer
17:10 Summary

DISCLAIMER - The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free content each week!

#python #softwaredesign

Dependency INVERSION VS Dependency INJECTION in Python