Skip to content

cemrehancavdar/di-why-and-how

Repository files navigation

Learn Dependency Injection in Python

This is a step-by-step guide to learn Dependency Injection (DI) in Python. Each section has working code examples that you can run and experiment with.

What You'll Learn

  1. Why Dependency Injection?

    • Problems with tightly coupled code
    • How DI makes code better
    • Simple database example
  2. Basic Patterns

    • What is Dependency Injection?
    • Real example with notification system
    • Different ways to inject dependencies
  3. IoC Principles

    • What is Inversion of Control?
    • Event-based systems
    • How frameworks use IoC
  4. DI Container

    • What is a DI container?
    • How to register services
    • How to resolve dependencies
  5. Web Application

    • Real example using Litestar
    • How to structure a web app with DI
    • How to test code with DI

How to Use This Guide

  1. Start from section 1 and move forward
  2. Each folder has:
    • Code examples you can run
    • README explaining the concepts
    • Problems and solutions

Requirements

  • Python 3.8 or newer
  • Basic Python knowledge
  • For web app example: pip install litestar ...

Note: Check out my_brain_dump.py - my first attempt at building a DI container. It might be weird, but "it's nice" 😄

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages