Philipp Mayer
12/30/2020, 12:50 PMfun Application.rooms(db: DB) {
install(Koin) {
modules(roomsDI)
}
val roomFooBar: RoomFooBar by inject()
routing {
roomRoutes(roomFooBar)
}
}
val roomsDI = module {
single<RoomFooBar> { RoomService(get()) }
single<RoomRepository> { RoomDatabaseAccessor(???)}
}
class RoomDatabaseAccessor(private val db: DB) : RoomRepository {...}
I'm not sure how to pass the db
parameter (which is a function parameter of Application.rooms()
) into the koin module. The parameter changes depending on the context, so just declaring it inside the module { }
would not work.
Any hints for that? I could not really find a satisfying solution in the docs.
Thanks a lot!Florian Eula
12/30/2020, 2:57 PMfun roomsDi(db: DB) = module {
single<Database> { db }
single<RoomFooBar> { RoomService(get()) }
single<RoomRepository> { RoomDatabaseAccessor(db) }
}
Philipp Mayer
12/30/2020, 3:09 PM