Applications
All Doodle apps run within an Application
. It is the entry-point for your business logic, and often the first class you write. Doodle fully initializes your app at constructor time, so there is no additional run or start method to implement. You can provide custom tear-down logic via the shutdown
method though.
import io.nacular.doodle.application.Application
//sampleStart
class UsefulApp: Application {
init {
println("Hi!")
}
override fun shutdown() {}
}
//sampleEnd
Launching an application
You can either launch an app top-level, or nested within another app (web). The Application class does not change regardless of the launch mode. That is because apps have no knowledge of the mode they will run in, making them independent of platform concepts by default.
App launch is platform-specific, allowing apps to customize their setup based on this context.
Top-level applications
Most apps will run independent of others and exist purely within the context of a window. Use the application
(Web, Desktop) function to launch apps this way. The result is a full-screen experience, with the app taking up the entire window and controlling all aspects of it.
package usefulapp
import UsefulApp
import io.nacular.doodle.application.application
//sampleStart
fun main() {
// launch full-screen
application {
UsefulApp()
}
}
//sampleEnd
Doodle web apps can also be hosted in HTML elements.
Nested applications (Web)
Doodle web apps can also be run within other Doodle Web apps.
Modularity
Doodle uses dependency injection when creating apps. The lambda provided when launching an app is actually a Kodein binding context that lets you inject instances from Doodle modules, or your own.
package applications
import io.nacular.doodle.application.Modules.Companion.PointerModule
import io.nacular.doodle.application.application
import org.kodein.di.DI.Module
import org.kodein.di.instance
//sampleStart
fun main() {
application(modules = listOf(
PointerModule,
// ...,
Module(name = "A Custom Module") {
// custom Kodein bind statements
},
/*...*/)) {
MyApp(instance())
}
}
//sampleEnd