2015-09-02 12:23:01 +03:00
|
|
|
"""`@di.inject()` decorator simple example."""
|
2015-08-05 17:01:23 +03:00
|
|
|
|
2015-09-01 19:08:35 +03:00
|
|
|
import dependency_injector as di
|
2015-08-05 17:01:23 +03:00
|
|
|
|
|
|
|
|
2015-09-01 19:08:35 +03:00
|
|
|
dependency_injector_factory = di.Factory(object)
|
2015-08-05 17:01:23 +03:00
|
|
|
|
|
|
|
|
2015-10-23 15:04:04 +03:00
|
|
|
# Example of using `di.inject()` decorator keyword argument injections:
|
2015-09-01 19:08:35 +03:00
|
|
|
@di.inject(new_object=dependency_injector_factory)
|
|
|
|
@di.inject(some_setting=1334)
|
2015-10-23 15:04:04 +03:00
|
|
|
def example_callback1(new_object, some_setting):
|
2015-09-01 22:30:49 +03:00
|
|
|
"""Example callback that does some asserts for input args."""
|
2015-08-05 17:01:23 +03:00
|
|
|
assert isinstance(new_object, object)
|
|
|
|
assert some_setting == 1334
|
|
|
|
|
2015-10-23 15:04:04 +03:00
|
|
|
|
|
|
|
# Example of using `di.inject()` decorator with positional argument injections:
|
|
|
|
@di.inject(dependency_injector_factory, 1334)
|
|
|
|
def example_callback2(new_object, some_setting):
|
|
|
|
"""Example callback that does some asserts for input args."""
|
|
|
|
assert isinstance(new_object, object)
|
|
|
|
assert some_setting == 1334
|
|
|
|
|
|
|
|
|
|
|
|
example_callback1()
|
|
|
|
example_callback2()
|