Closed chrisgoddard closed 10 months ago
@chrisgoddard hello again and thanks for your pleasure feedback about projects
Depends
are parsing incoming functional (not dafault) arguments to use some of them as an own incoming arguments too. To support parametrize dependencies you can use them like this
from fast_depends import Depends, inject
def parametrize_dependency(argument: int):
def real_dependency(function_argument: int):
return argument + function_argument
return real_dependency
@inject
def call(d = Depends(parametrize_dependency(1))):
return d
assert call(1) == 2
or use a callable class
class ParamDep:
def __init__(self, param):
self.param = param
def __call__(self, function_argument):
return function_argument + self.param
Also, Depends
can be nested in each other (as a Context too), so you can use this feature as well
Also, thanks for being with the Propan project since it start Can you give us any feedback about its usage?
Hey there! Me again šµāš« (btw - big fan of this and the FastStream project!)
Running into this issue in the context of FastStream.
The following code works as expected:
testing_a correctly receives message: ComplexMessage and the redis client instance is available.
However, if change my
inject_redis_client
function to accept an argument, for instance:Then when I run the app I get the following error:
In this context, I'm not passing a
redis_db
argument to the testing_a function - but that shouldn't matter as it's optional.Even if I update the function to set a value:
I get the same issue.
I might not 100% be understanding how you're supposed to pass arguments to dependency injection functions but nothing I try seems to make a difference.