注入不能与第二个构造函数一起使用
对于我当前的项目,我正在使用Kotlin和Dagger 2.我想在二级构造函数中注入依赖项,但构造函数从未初始化。
class SelectionFragmentModel ():ViewModel(){ lateinit var channelInfosRepository: ChannelInfosRepository @Inject constructor(channelInfosRepository: ChannelInfosRepository) : this(){ this.channelInfosRepository = channelInfosRepository } ... }
作为一种解决方法,我目前正在注入主构造函数,但这不是最佳的。
class SelectionFragmentModel @Inject constructor(private val channelInfosRepository: ChannelInfosRepository):ViewModel(){ constructor() : this(ChannelInfosRepository()) ... }
我错过了什么吗?