how can I get DI in a class that should not have a...
# kodein
k
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
Copy code
class TTSService(override val di: DI) : MediaBrowserServiceCompat(), AudioManager.OnAudioFocusChangeListener, DIAware {
then there will be an error in manifest that say
Copy code
This class should provide a default constructor (a public constructor with no arguments) (ireader.domain.services.tts_service.media_player.TTSService)
is there any way to use services using kodein?
I fix this by a trick first use lateinit for di like this:
Copy code
override lateinit var di: DI
then in onCreate in service I initialize it like this
Copy code
override fun onCreate() {
        di = (this@TTSService.application as DIAware).di
        super.onCreate()
h
I think this is the only way to do it, since the android system calls the (empty) constructor for you.