-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
[WIP] Provide a way to inject request-scoped dependencies in Guice #6798
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
Conversation
|
This could eventually be used as an alternative to |
|
Great! It will work as expected with the But, if the controllers are annotated with Will it have any (negative) impact on performance? |
The main concern I have is the performance impact creating a child injector. I tried looking at using a The cost of creating new instances is not really a problem. Normally it only makes sense to use |
|
Looking at this validator class does it mean we could just inject a component (like we do with messagesApi) to replace Http.Context.current.get()? That would be awesome, specially since there is now way to pass the current context into the Also we could inject such components into the |
|
@mkurz Actually, it wouldn't work as I wrote it right now, because the |
046da10 to
464d91d
Compare
|
It seems like child injectors are the right way to achieve what we want to do (see https://groups.google.com/d/msg/google-guice/qZqkaWPkhoo/tcCRWNmIDQAJ). One issue is that child injectors can't override bindings from the parent module, but we can't access the request unless the binding was in a request scoped module. So we probably have to separate out the request-scoped things into a separate Play module, so we can bind them only in the child injector. |
|
Closing since this is not likely to happen, at least not in this form. If someone wants to pick this up and continue working on it, it should be possible to do it in another project. It's also possible you could make a request-scoped |
The work is mostly based in the code from this pull request on play-framework project [1]. [1] - playframework/playframework#6798
This defines a
RequestScopedRouterclass that can be extended with Guice modules to allow injecting theRequestHeaderand other dependencies that use aRequestHeader.