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