Why can't I inject into secondary Constructor?


#1

Hello,
for my current project I’m using Kotlin and Dagger 2. I want to inject dependencies in an secondary constructor, but the constructor never gets initialized.

class SelectionFragmentModel ():ViewModel(){
   lateinit var channelInfosRepository: ChannelInfosRepository
   @Inject constructor(channelInfosRepository: ChannelInfosRepository) : this(){
      this.channelInfosRepository = channelInfosRepository
   }
   ...
}

As a workaround I’m currently injecting in the primary constructor but this isn’t optimal.

class SelectionFragmentModel @Inject constructor(private val channelInfosRepository: ChannelInfosRepository):ViewModel(){
   constructor() : this(ChannelInfosRepository())
   ...
}

Am I missing something?