python-dependency-injector/examples/inject_decorator2.py

24 lines
547 B
Python
Raw Normal View History

2015-03-31 14:44:15 +03:00
"""`@inject` decorator example."""
from objects.providers import NewInstance
from objects.injections import KwArg
from objects.decorators import inject
2015-03-31 14:44:15 +03:00
2015-03-31 18:00:11 +03:00
new_object = NewInstance(object)
2015-03-31 14:44:15 +03:00
2015-03-31 18:00:11 +03:00
@inject(KwArg('object_a', new_object))
@inject(KwArg('some_setting', 1334))
def example_callback(object_a, some_setting):
2015-03-31 14:44:15 +03:00
"""This function has dependencies on object a and b.
Dependencies are injected using `@inject` decorator.
"""
2015-03-31 18:00:11 +03:00
assert isinstance(object_a, object)
assert some_setting == 1334
2015-03-31 14:44:15 +03:00
example_callback()
2015-03-31 18:00:11 +03:00
example_callback()