Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass context objects to MethodAnnotation decorators at runtime #143

Closed
prkumar opened this issue Feb 25, 2019 · 0 comments · Fixed by #155
Closed

Pass context objects to MethodAnnotation decorators at runtime #143

prkumar opened this issue Feb 25, 2019 · 0 comments · Fixed by #155

Comments

@prkumar
Copy link
Owner

prkumar commented Feb 25, 2019

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 with Context(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 the request_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

@prkumar prkumar pinned this issue Feb 27, 2019
@prkumar prkumar added this to the v0.9.0 milestone Mar 2, 2019
@prkumar prkumar unpinned this issue Apr 30, 2019
@prkumar prkumar mentioned this issue Jun 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant