Skip to content

Instantly share code, notes, and snippets.

@joshafeinberg
Created February 29, 2020 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshafeinberg/88161f1c7fd25c87608ae80a131ba6fa to your computer and use it in GitHub Desktop.
Save joshafeinberg/88161f1c7fd25c87608ae80a131ba6fa to your computer and use it in GitHub Desktop.
fun Application.kodeinApplication(
kodeinMapper: Kodein.MainBuilder.(Application) -> Unit = {}
) {
val application = this
val kodein = Kodein {
bind<Application>() with instance(application)
kodeinMapper(this, application)
}
routing {
val sicknessService: SicknessService = findService(kodein)
val weightService: WeightService = findService(kodein)
val statsService: StatsService = findService(kodein)
retrofitService(service = Services(
sicknessService = sicknessService,
weightService = weightService,
statsService = statsService
))
}
}
private inline fun <reified S : Any> findService(kodein: Kodein): S {
val service: S by kodein.instance()
return service
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment