ron
03/12/2017, 5:25 PMedvin
03/12/2017, 5:25 PMedvin
03/12/2017, 5:26 PMron
03/12/2017, 10:48 PMcarlw
03/12/2017, 10:50 PMedvin
03/13/2017, 7:42 AMcarlw
03/13/2017, 2:04 PMgtnarg
03/13/2017, 2:06 PMron
03/13/2017, 2:52 PMron
03/13/2017, 2:52 PMgtnarg
03/13/2017, 3:47 PMval helloBean : HelloBean by di("beanName")
gtnarg
03/13/2017, 3:50 PMron
03/13/2017, 4:15 PMorangy
ron
03/13/2017, 7:53 PMgtnarg
03/13/2017, 7:54 PMron
03/13/2017, 8:11 PMxml
<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:
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 as the id of the bean. Instantiating a bean is down as:
val helloBean : HelloBean by di("beanName")
gtnarg
03/13/2017, 8:14 PMand
id of the bean. The bean can be injected by: val helloBean : HelloBean by di("helloWorld")
(to be consistent with the xml).carlw
03/13/2017, 8:15 PMron
03/13/2017, 8:16 PMxml
<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:
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:
val helloBean : HelloBean by di("helloWorld")
ron
03/13/2017, 8:19 PMron
03/13/2017, 8:27 PMedvin
03/13/2017, 8:30 PMedvin
03/13/2017, 8:31 PMron
03/13/2017, 8:31 PMedvin
03/13/2017, 8:37 PMron
03/13/2017, 8:37 PMron
03/13/2017, 8:38 PMedvin
03/13/2017, 8:40 PM