mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-07-06 13:23:15 +03:00
Add support of corouting functions
This commit is contained in:
parent
f3619d696f
commit
9ffe2a31c6
|
@ -176,15 +176,26 @@ def _fetch_modules(package):
|
||||||
|
|
||||||
|
|
||||||
def _patch_with_injections(fn, injections):
|
def _patch_with_injections(fn, injections):
|
||||||
@functools.wraps(fn)
|
if inspect.iscoroutinefunction(fn):
|
||||||
def _patched(*args, **kwargs):
|
@functools.wraps(fn)
|
||||||
to_inject = {}
|
async def _patched(*args, **kwargs):
|
||||||
for injection, provider in injections.items():
|
to_inject = {}
|
||||||
to_inject[injection] = provider()
|
for injection, provider in injections.items():
|
||||||
|
to_inject[injection] = provider()
|
||||||
|
|
||||||
to_inject.update(kwargs)
|
to_inject.update(kwargs)
|
||||||
|
|
||||||
return fn(*args, **to_inject)
|
return await fn(*args, **to_inject)
|
||||||
|
else:
|
||||||
|
@functools.wraps(fn)
|
||||||
|
def _patched(*args, **kwargs):
|
||||||
|
to_inject = {}
|
||||||
|
for injection, provider in injections.items():
|
||||||
|
to_inject[injection] = provider()
|
||||||
|
|
||||||
|
to_inject.update(kwargs)
|
||||||
|
|
||||||
|
return fn(*args, **to_inject)
|
||||||
|
|
||||||
_patched.__wired__ = True
|
_patched.__wired__ = True
|
||||||
_patched.__original__ = fn
|
_patched.__original__ = fn
|
||||||
|
|
Loading…
Reference in New Issue
Block a user