I have functionality common to multiple screen controllers, so I decided to make a new package in the web module, i.e. com.mycompany.abc.web.utils, and a new class MyClass.java in this package.
I would like to Inject some of my Middleware Services, and ExportDisplay in MyClass, but injected elements are null. Is the only way of doing this to register MyClass as JavaBean and making it a singleton?
You can use injection for any class, even if it’s not a spring bean. E.g. we use injections for test classes.
You have to:
Copy class com.haulmont.cuba.gui.ControllerDependencyInjector to your own MyDependencyInjector and remove all GUI-related stuff from the code.
For every instance of your class you have to instantiate MyDependencyInjector and call myDependencyInjector.inject()
You will have to do it manually right after your object’s instantiation, or invent how to automate it.
E.g. for test classes there are lifecycle rules and annotations.