I'm using JavaFX, where you create a class that extends JavaFX Application, and then you pass the class to JavaFX's launch method. Inside the Application class you override the start method which gets an instance of Stage passed into it.
How can I make this instance of Stage available as a dependency for other objects?
// Kotlin
fun main() {
launch(MyApplication::class.java)
}
class MyApplication : Application()
{
override fun start(stage: Stage)
{
// I want other objects to be able to have stage injected into them.
val myWindow = MyWindow
stage.run {
scene = Scene(myWindow, 800.0, 600.0)
show()
}
}
}
In Spring I think you would do something like this
// Java
Object externalyDefinedBean = ...;
GenericApplicationContext parentContext = new StaticApplicationContext();
parentContext.getBeanFactory().registerSingleton("injectedBean", externalyDefinedBean);