amanda.hinchman-dominguez
01/22/2019, 9:27 PMinject()
is for singleton components (Models()
, Views()
, Controllers()
) which is TornadoFX specific. For di()
, you can inject third party resources by creating an FX.dicontainer
Czar
01/23/2019, 7:35 AMby di()
works, but in tornadofx we have two APIs.amanda.hinchman-dominguez
01/28/2019, 4:08 PMedvin
01/28/2019, 4:34 PMinject()
for an abstraction which would support other mechanisms as well, but still provide a default implementation.amanda.hinchman-dominguez
01/28/2019, 4:36 PMCzar
01/28/2019, 5:08 PMinternal val koFu = application {
//SpringFu config
}
class MyAppUi : App(LoginScreen::class) {
override fun init() {
koFu
//init SpringFu context
.run()
.also { applicationContext ->
FX.dicontainer = object : DIContainer {
override fun <T : Any> getInstance(type: KClass<T>): T =
applicationContext.getBean(type.java)
override fun <T : Any> getInstance(type: KClass<T>, name: String): T =
applicationContext.getBean(name, type.java)
}
}
}
}
this snippet is basically teaching TFX how to use external DI by just overriding two methods that are more or less universally provided by other containers. Only way to simplify this configuration, I think, would be to provide declarative integration for most popular DI frameworks out of the box, but I do not really think that necessary. It could look something like this in case of SpringFu:
internal val koFu = application {
//SpringFu config
}
class MyAppUi : App(LoginScreen::class) {
override fun init() {
koFu
//init SpringFu context
.run()
.also(FX::useSpringContext)
}
}
Hm... looks better, maybe we should, after all there are not too many popular DI containers out there.edvin
01/28/2019, 5:25 PMamanda.hinchman-dominguez
01/28/2019, 5:26 PMinject()
right now can only use the types that are Injectable
which is extended by ScopedInstance
. My question for injecting 3rd party beans is "how often will we ever need to override getInstances other than by type or id
?" Perhaps you're right @Czar, it would be worth providing at least a refactor to simplify the code for creating a DI container for popular di frameworks like say, Spring, SpringFu, Daggeredvin
01/28/2019, 5:27 PMCzar
01/28/2019, 5:28 PMamanda.hinchman-dominguez
01/28/2019, 5:29 PMedvin
01/28/2019, 5:29 PMamanda.hinchman-dominguez
01/28/2019, 5:29 PMedvin
01/28/2019, 5:30 PMamanda.hinchman-dominguez
01/28/2019, 5:32 PMamanda.hinchman-dominguez
01/28/2019, 5:32 PMedvin
01/28/2019, 5:33 PMamanda.hinchman-dominguez
01/28/2019, 5:36 PMCzar
01/28/2019, 5:38 PMInjectionPoint
something that exists in TFX already, or is it a new idea?edvin
01/28/2019, 5:38 PMedvin
01/28/2019, 5:38 PMedvin
01/28/2019, 5:39 PMedvin
01/28/2019, 5:39 PMamanda.hinchman-dominguez
01/28/2019, 5:40 PMCzar
01/28/2019, 5:40 PMedvin
01/28/2019, 5:41 PMamanda.hinchman-dominguez
01/28/2019, 5:42 PMCzar
01/28/2019, 5:42 PMAlexCzar
edvin
01/28/2019, 5:48 PMamanda.hinchman-dominguez
01/28/2019, 5:48 PMamanda.hinchman-dominguez
01/28/2019, 5:48 PMedvin
01/28/2019, 5:49 PMfind
implementation.amanda.hinchman-dominguez
01/28/2019, 5:50 PMedvin
01/28/2019, 5:50 PMCzar
01/28/2019, 6:59 PMprototype
(Spring) and dependent
(CDI) beans, which makes sense if you think about it. CDI will actually even throw an exception if you try to use it on anything but dependent
, Spring took a weird route of giving you the first encountered point instead.amanda.hinchman-dominguez
01/28/2019, 7:00 PMedvin
01/28/2019, 7:01 PMCzar
01/28/2019, 7:03 PMedvin
01/28/2019, 7:04 PMCzar
01/28/2019, 7:05 PMedvin
01/28/2019, 7:05 PMedvin
01/28/2019, 7:05 PMCzar
01/28/2019, 7:06 PMamanda.hinchman-dominguez
01/28/2019, 7:09 PMCzar
01/28/2019, 7:13 PMclass MyController: Controller()
class View1 {
@AnnotationOne
val myController: MyController by inject()
}
class View2 {
@AnnotationTwo
val myController: MyController by inject()
}
MyController
is a singleton and it is injected into two different views, which specify two different annotations, which annotation should be taken into account during MyController
instantiation?amanda.hinchman-dominguez
01/28/2019, 7:14 PMamanda.hinchman-dominguez
01/28/2019, 7:15 PMedvin
01/28/2019, 7:15 PMedvin
01/28/2019, 7:15 PMCzar
01/28/2019, 7:16 PMamanda.hinchman-dominguez
01/28/2019, 7:17 PMamanda.hinchman-dominguez
01/28/2019, 7:18 PMCzar
01/28/2019, 7:18 PMedvin
01/28/2019, 7:18 PMCzar
01/28/2019, 7:18 PMedvin
01/28/2019, 7:19 PMamanda.hinchman-dominguez
01/28/2019, 7:20 PMCzar
01/28/2019, 7:20 PMCzar
01/28/2019, 7:22 PMedvin
01/28/2019, 7:22 PMCzar
01/28/2019, 7:25 PMCzar
01/28/2019, 7:26 PMedvin
01/28/2019, 7:26 PMCzar
01/28/2019, 7:29 PMedvin
01/28/2019, 7:29 PMamanda.hinchman-dominguez
01/28/2019, 7:29 PMamanda.hinchman-dominguez
01/29/2019, 12:57 PMamanda.hinchman-dominguez
01/29/2019, 12:58 PMamanda.hinchman-dominguez
01/29/2019, 12:58 PMedvin
01/29/2019, 8:11 PMamanda.hinchman-dominguez
01/29/2019, 8:12 PMamanda.hinchman-dominguez
01/29/2019, 8:13 PMedvin
01/29/2019, 8:14 PMedvin
01/29/2019, 8:14 PMamanda.hinchman-dominguez
01/29/2019, 8:14 PMamanda.hinchman-dominguez
01/29/2019, 8:14 PMamanda.hinchman-dominguez
01/29/2019, 8:15 PMedvin
01/29/2019, 8:15 PMedvin
01/29/2019, 8:16 PMamanda.hinchman-dominguez
01/29/2019, 8:16 PMedvin
01/29/2019, 8:16 PMamanda.hinchman-dominguez
01/29/2019, 8:17 PMedvin
01/29/2019, 8:17 PMamanda.hinchman-dominguez
01/29/2019, 8:17 PMedvin
01/29/2019, 8:18 PMCzar
01/29/2019, 8:31 PMCzar
01/29/2019, 8:32 PMamanda.hinchman-dominguez
01/29/2019, 9:42 PMCzar
01/30/2019, 11:45 AMedvin
01/30/2019, 12:12 PMedvin
01/30/2019, 12:16 PMCzar
01/30/2019, 12:20 PMCzar
01/30/2019, 12:26 PMamanda.hinchman-dominguez
01/30/2019, 2:28 PMamanda.hinchman-dominguez
01/31/2019, 5:16 PMamanda.hinchman-dominguez
01/31/2019, 5:16 PMCzar
01/31/2019, 5:21 PMInjectionPoint
, but haven't had much time to engage otherwise. Doesn't look like I'll be able to before the weekend.amanda.hinchman-dominguez
01/31/2019, 5:22 PM