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

22 lines
568 B
Python
Raw Normal View History

2016-06-02 17:25:45 +00:00
"""@inject decorator example."""
from container import Container
from dependency_injector.injections import inject
2016-06-02 21:47:10 +00:00
@inject(car_factory=Container.car_factory.delegate())
@inject(extra_engine=Container.engine_factory)
def main(car_factory, extra_engine):
2016-06-02 17:25:45 +00:00
"""Main function."""
2016-06-02 21:47:10 +00: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 17:25:45 +00:00
assert car1.engine is not car2.engine
2016-06-02 21:47:10 +00:00
assert car2.engine is extra_engine
2016-06-02 17:25:45 +00:00
if __name__ == '__main__':
main()