Hello,
How can I use Pinject to inject dependencies into decorators?
For example, say I have a decorator like:
# foo.py
def cache_decorator(cache_client):
def decorator(func):
def wrapper(*args, **kwargs):
cache_client.read()
result = func(*args, **kwargs)
cache_client.write
return result
return wrapper
return decorator
class A:
@cache_decorator(dependency_I_want_to_inject)
def foo(bar):
bar.baz()
The goal is to swap the cache_client with a mock for unit testing.
Is something like this possible with Pinject?