2015-03-31 14:44:15 +03:00
|
|
|
"""`@inject` decorator example."""
|
|
|
|
|
|
|
|
from objects.providers import NewInstance
|
|
|
|
from objects.injections import KwArg
|
2015-04-14 23:17:53 +03:00
|
|
|
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()
|