It is quite common in the Spring world to name a b...
# tornadofx
r
It is quite common in the Spring world to name a bean like so:
Copy code
xml
<bean id = "helloWorld" class = "com.tutorialspoint.HelloWorld">
     <property name = "message" value = "Hello World!"/>
</bean>
The bean is then accessible using the
id
. This can be done in tornadoFX too:
Copy code
kotlin
class SpringExampleApp : App(SpringExampleView::class) {
    init {
        val springContext = ClassPathXmlApplicationContext("beans.xml")
        FX.dicontainer = object : DIContainer {
            override fun <T : Any> getInstance(type: KClass<T>): T = springContext.getBean(type.java)
	        override fun <T : Any> getInstance(type: KClass<T>, name: String): T = springContext.getBean(type.java,name)
        }
    }
}
The second
getInstance
uses both the type of the bean and the id of the bean. Instantiating a bean is down as:
Copy code
val helloBean : HelloBean by di("helloWorld")
👍 3