My questions relate to the life cycle of controllers in the Play platform for Java, if the controllers are stateless instances or have no state with static methods and how to use dependency injection in the controller code.
Each web request is processed by a new instance of the Play controller class, that is, can the storage status of the controller be in fields such as services entered into the controller’s constructor? (where does the documentation explain?)
Is the playback structure changed from earlier versions (and if so, in which version?) Regarding the fact that the controllers are stateless or stateless controllers with static methods?
Where can you see code examples on how the infrastructure deploys services to a controller instance when using a state controller and an example of how to inject services into a static controller method?
As for the latter, that is, injections into a static method, I believe that this should either be a parameter of the method to be added by the frameworks, or if this is not possible, you may have to use the service locator from the method, for example, create an instance of the Guice module class and then use "injector.getInstance" from the static controller method.
This issue is addressed in the Dependency Injection Controllers section of the following page:
https://www.playframework.com/documentation/2.4.x/JavaDependencyInjection
However, it does not show with the code how to actually embed services in the controller instance (but, probably, in the same way as other "components", i.e. with the @Inject annotation), and, of course, it does not currently show How to use DI with a static controller.
I got confused about these things because I did not find the documentation in which my questions were clear, and I also read in the Play Book (since 2013) that controller methods should be programmed as stateless, and controller methods should be static.
However, if I now use the activator to create a Play application for Java with the latest version of Play (2.4.6), I see that the generated Controller method (Application.index) is not static. In addition, on the next page of the documentation, the controller method is NOT static: https://www.playframework.com/documentation/2.4.x/JavaActions
This is confusing, and since it is VERY important to understand whether each request is processed by the controller instance or not (i.e. if the state can be used), I think that this should be better described on the controller / actions page than the current documentation ( link above) which does not explain this.
The dependency injection documentation covers the topic of static and non-static methods in the section "Dependency Injection Controllers" which mention the "static route generator", but I think this should be better explained, including code examples.
If someone from the Play team reads this question, please add some information to the above related pages, for example, please indicate (if I understood correctly) that in previous versions of Play the controller methods were static and for these versions you should never store state in fields, but in later versions (starting with version x?) each request is processed by the controller instance and therefore can use state (for example, designer parameters entered by the framework).
Please also provide code examples regarding injections used with static controller methods and insertion into state controller instances with one instance for each request.
In the “Component Life Cycle” section of the dependency entry page, only “components” are mentioned, but I think that it should also be explicit about the life cycle of the controller and its introduction, since it is such fundamental and important knowledge that should be clearly communicated to all developers to avoid errors caused by misunderstandings about being restrained or not.