Kazem Moridi

02/26/2023, 6:46 PM
how can I get DI in a class that should not have a constructor because its a android service that play music in background, if I add di like this
class TTSService(override val di: DI) : MediaBrowserServiceCompat(), AudioManager.OnAudioFocusChangeListener, DIAware {
then there will be an error in manifest that say
This class should provide a default constructor (a public constructor with no arguments) (
is there any way to use services using kodein?
I fix this by a trick first use lateinit for di like this:
override lateinit var di: DI
then in onCreate in service I initialize it like this
override fun onCreate() {
        di = (this@TTSService.application as DIAware).di

Hylke Bron

02/27/2023, 7:32 AM
I think this is the only way to do it, since the android system calls the (empty) constructor for you.