We’re working on a project where the business logic is implemented in a separate module using non-TornadoFX types. There’s a (non-TornadoFX) event system in place and we're using Dagger for dependency injection. We want to build a TornadoFX UI on top of this.
We're struggling with:
Integrating Dagger's (static, compile-time) dependency injection system with TornadoFX's injection principles.
Grasping the conceptual role of Controllers as TornadoFX's Views acts as ViewControllers (as discussed here).
A simplified example would be:
data class Entry(...)
interface EntryDao {
val allEntries: List<Entry>
fun register(listener: EntryListener)
}
Our approach would be to:
Create an EntryController that gets the EntryDao injected (and optionally creates an EntryViewModel, as in the withpojo example). This EntryController would register on EntryDao's changes.
@Singleton
class EntryController @Inject constructor (private val entryDao: EntryDao) { ... }
Create one (or more) View(s) that visualize data from (and possibly trigger actions using) the EntryController obtained using by di().
class EntryView : View() {
val controller: EntryController by di()
...
}
Implement the DIContainer interface in a way that all Controllers (and their dependencies) are created and wired automagically using Dagger.
@Singleton
class Controllers @Inject constructor(entryController: EntryController, ...) {
...
fun <T : Any> getInstance(type: KClass<T>): T { ... }
}
We’re working on a project where the business logic is implemented in a separate module using non-TornadoFX types. There’s a (non-TornadoFX) event system in place and we're using Dagger for dependency injection. We want to build a TornadoFX UI on top of this.
We're struggling with:
Controller
s as TornadoFX'sView
s acts asViewController
s (as discussed here).A simplified example would be:
Our approach would be to:
Create an
EntryController
that gets theEntryDao
injected (and optionally creates anEntryViewModel
, as in the withpojo example). ThisEntryController
would register onEntryDao
's changes.Create one (or more)
View
(s) that visualize data from (and possibly trigger actions using) theEntryController
obtained usingby di()
.Implement the
DIContainer
interface in a way that allController
s (and their dependencies) are created and wired automagically using Dagger.Would this be the best way of tackling this?