python-dependency-injector/examples/speech/inject.py

22 lines
570 B
Python
Raw Normal View History

2016-06-02 20:25:45 +03:00
"""@inject decorator example."""
from container import Container
from dependency_injector.injections import inject
2016-06-03 00:47:10 +03:00
@inject(car_factory=Container.car_factory.delegate())
@inject(extra_engine=Container.engine_factory)
def main(car_factory, extra_engine):
2017-04-18 23:38:04 +03:00
"""Run application."""
2016-06-03 00:47:10 +03:00
car1 = car_factory(serial_number=1)
car2 = car_factory(serial_number=2, engine=extra_engine)
assert car1.serial_number == 1 and car2.serial_number == 2
2016-06-02 20:25:45 +03:00
assert car1.engine is not car2.engine
2016-06-03 00:47:10 +03:00
assert car2.engine is extra_engine
2016-06-02 20:25:45 +03:00
if __name__ == '__main__':
main()