tornadofx-idea-plugin
tornadofx-idea-plugin copied to clipboard
DI container support for single view run configurations
If FX.dicontainer is set only from application entry point then it's not initialized upon View launch leading to AssertionError in delegates.
It would come in handy to have an ability to configure DI container for View run configuration.
Maybe this could be generalized by allowing you to call an arbitrary function before the View is executed? I'm not sure of the value though, as you might as well just execute an App endpoint in that case. How do you envision this?
As I see, in the App.kt code, there is an argument for patching primary view if it's not set, probably another argument could be added for overriding?
Right now our project is Wizard-based, so I just comment out views I'm not working on from Wizard init block and use application run configuration.
I meant, that another argument could be added in App class, but the launched app will be it's ancestor, not the plain App.
I added a --di-container=classname parameter to TornadoFX. You can try it out by adding a parameter in the View run configuration. If this works as expected for you, I'll add a field to the UI of the plugin run configuration as well.
Well, this looks like only a partial solution, because it's not quite consistent with Spring Boot, for example, where DI container is dependant on Spring context received from SpringApplication::run which depends on application arguments and Spring beans source class[es].
A common approach with FX apps is to run Spring Boot application in javafx.application.Application::init.
I haven't had experience writing IDEA plugins yet, but I'll try adding View overriding possibility to the "App" run configuration in near future.