-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Injection parameters to methods of controllers #10873
Comments
This would need experimenting to see if something like this is even possible with the way Play's routing and action methods calls work right now. So, if I understand correctly, you don't want to repeat the call of ACHost acHost = request.attrs().getOptional(AC_HOST_PARAM).get(); // for example call Optional.get() in each action method. What about adding a small helper method like: private static ACHost acHost(Http.Request req) {
return request.attrs().getOptional(AC_HOST_PARAM).get(); // for example call Optional.get()
} So, you can just call |
@mkurz Thank you for your response. The helper can help, but our main idea is "Use our domain objects in the signatures of our methods of controllers without additional helpers, Play's |
@Captain1653 sure. However, to be honest, such a feature isn't priority right now. Sure it would be nice to have, but there a lot of things which would be nice to have. Feel free to provide a pull request anytime. |
@mkurz Can you give me some starting point for my research? Some classes, documentation and etc... Play Framework has similar approach, but the approach requires :
Our new approach calls DB or does other HTTP-request (unlikely to happen). |
Maybe it relates to #2983 (in some way). We use multi-tenant data isolation. Our main entity is AcHost. We need to transfer it in many controllers without copy/paste. We use action composition .
Our current solution works like that:
And it looks really bad.
It will be cool to inject our entity directly in controller like that:
Is it possible to implement?
We have some idea about API for the feature (maybe it will be useful)
Declare in routes-file
GET /some/url controllers.CreationRestrictionsController.creationRestrictionsPage(acHost: AcHost)
Use in jsRoutes
jsRoutes.controllers.CreationRestrictionsController.creationRestrictionsPage() // without additional params
It would be really useful for our team.
Kind regards
The text was updated successfully, but these errors were encountered: