对于我当前的项目,我正在使用Kotlin和Dagger 2.我想在辅助构造函数中注入依赖项,但构造函数永远不会被初始化.
class SelectionFragmentModel ():ViewModel(){
lateinit var channelInfosRepository: ChannelInfosRepository
@Inject constructor(channelInfosRepository: ChannelInfosRepository) : this(){
this.channelInfosRepository = channelInfosRepository
}
...
}
Run Code Online (Sandbox Code Playgroud)
作为一种解决方法,我目前正在主要构造函数中注入,但这不是最佳的.
class SelectionFragmentModel @Inject constructor(private val channelInfosRepository: ChannelInfosRepository):ViewModel(){
constructor() : this(ChannelInfosRepository())
...
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?