holgerbrandl
12/20/2022, 11:31 AMimport org.koin.dsl.koinApplication
import org.koin.dsl.module
data class Tester(val id:String, val created :Long ){
init{
println("creating $this")
}
}
fun main() {
val myModule= module(createdAtStart = true) {
single(createdAtStart = true){
Tester("A", System.nanoTime())
}
}
val koinApplication = koinApplication {}
val koin = koinApplication.koin
koin.loadModules(modules = listOf(myModule))
println("everything loaded?")
println(koin.get<Tester>())
}
The print order changes between the mentioned versions. To me this qualifies as a bug.arnaud.giuliani
12/20/2022, 1:43 PMcreatedAtStartholgerbrandl
12/20/2022, 4:07 PMarnaud.giuliani
12/20/2022, 4:33 PMholgerbrandl
12/21/2022, 7:55 AMholgerbrandl
11/27/2025, 1:58 PMdata class Tester(val created: Long = System.nanoTime()){
init {
println("created")
}
}
val myModule = module(createdAtStart = true) {
single(createdAtStart = true) {
Tester()
}
}
val koinApplication = koinApplication {}
val koin = koinApplication.koin
koin.loadModules(modules = listOf(myModule))
println("post-creation")
val now = System.nanoTime()
sleep(10)
now shouldBeGreaterThan koin.get<Tester>().created
The output is
> post-creation
> created
What am I doing from to enforce createAtStart?arnaud.giuliani
12/01/2025, 8:03 AMkoinApplication you need to use createEagerInstances properties to create eager instances by hand: