2016-04-26 13:14:39 +03:00
|
|
|
"""Example of inversion of control container for Car & Engine example."""
|
|
|
|
|
2016-05-29 17:33:31 +03:00
|
|
|
from dependency_injector import containers
|
2016-04-26 13:14:39 +03:00
|
|
|
from dependency_injector import providers
|
|
|
|
|
|
|
|
from car_engine_ioc import Car
|
|
|
|
from car_engine_ioc import Engine
|
|
|
|
|
|
|
|
|
2016-05-29 17:33:31 +03:00
|
|
|
class Components(containers.DeclarativeContainer):
|
|
|
|
"""IoC container of component providers."""
|
2016-04-26 13:14:39 +03:00
|
|
|
|
|
|
|
engine = providers.Factory(Engine)
|
|
|
|
|
|
|
|
car = providers.Factory(Car, engine=engine)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
car = Components.car() # Application creates Car's instance
|