Pass context objects to MethodAnnotation
decorators at runtime
#143
Labels
Milestone
MethodAnnotation
decorators at runtime
#143
Is your feature request related to a problem? Please describe.
In this gitter comment, @kaidokert noted that there aren't any ways to make objects available to decorators at runtime. Notably, we were trying to pass a cache provider supplied as a constructor argument at runtime to a custom
cache
decorator.Describe the solution you'd like
What might be a neat idea to explore is adding a Context function annotation (i.e., ArgumentAnnotation subclass) that can be used to provide data to a
MethodAnnotation
. This way, you can annotate one of the constructor arguments withContext(key=cache.CACHE_PROVIDER)
, then the value of that argument becomes available to the@cache
decorator by querying a dictionary of context objects exposed through therequest_builder
(e.g.,request_builder.context[cache.CACHE_PROVIDER]
). Then, in cache.modify_request, you can check the existence of the cache-manager key in the request's context and conditionally add the cache RequestTemplate to the request builder if that key exists.Additional context
N/A
The text was updated successfully, but these errors were encountered: