python-dependency-injector/examples/ioc_di_demos/car_engine_ioc_container.py
2016-06-02 20:26:37 +03:00

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