edvin / tornadofx-idea-plugin

TornadoFX Plugin for IntelliJ IDEA
Apache License 2.0
73 stars 20 forks source link

DI container support for single view run configurations #56

Open pavlus opened 6 years ago

pavlus commented 6 years ago

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.

edvin commented 6 years ago

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?

pavlus commented 6 years ago

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.

pavlus commented 6 years ago

I meant, that another argument could be added in App class, but the launched app will be it's ancestor, not the plain App.

edvin commented 6 years ago

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.

pavlus commented 6 years ago

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.