mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-03-27 21:34:22 +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):
|
||||
@functools.wraps(fn)
|
||||
def _patched(*args, **kwargs):
|
||||
to_inject = {}
|
||||
for injection, provider in injections.items():
|
||||
to_inject[injection] = provider()
|
||||
if inspect.iscoroutinefunction(fn):
|
||||
@functools.wraps(fn)
|
||||
async def _patched(*args, **kwargs):
|
||||
to_inject = {}
|
||||
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.__original__ = fn
|
||||
|
|
Loading…
Reference in New Issue
Block a user