Use type hints to declare what a class needs. The framework uses these hints to "look up" the correct dependency.

A guide to implementing injector.py revolves around three main abstractions:

: The central orchestrator that builds the dependency graph and provides objects to your application. 3. Basic Implementation Guide Step A: Define Your Classes

If you have multiple implementations for one interface (e.g., a "TestDB" and a "LiveDB"), use a Module to specify which one to use.

: Use the @provider decorator inside a Module for more complex object creation that requires logic.

: The library is commonly used to simplify SOLID principles in frameworks like Django and FastAPI .

from injector import Injector injector = Injector([MyModule()]) # Pass your modules here service = injector.get(Service) # Automatically creates Database and Service print(service.db.status) # "Connected" Use code with caution. Copied to clipboard


injector.pyПодпишитесь на рассылку и получайте первым информацию о предстоящих мероприятиях

injector.py
+