mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-25 19:14:00 +03:00
20 lines
540 B
Python
20 lines
540 B
Python
"""Example of inversion of control container for Car & Engine example."""
|
|
|
|
import dependency_injector.containers as containers
|
|
import dependency_injector.providers as providers
|
|
|
|
import car_engine_ioc
|
|
|
|
|
|
class Container(containers.DeclarativeContainer):
|
|
"""IoC container of component providers."""
|
|
|
|
engine = providers.Factory(car_engine_ioc.Engine)
|
|
|
|
car = providers.Factory(car_engine_ioc.Car,
|
|
engine=engine)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
car = Container.car() # Application creates Car's instance
|