本文介绍了不推荐使用Dagger Hilt“辅助"和"ViewModelInject".在Dagger Hilt视图模型1.0.0-alpha03中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Dagger Hilt视图模型1.0.0-alpha01
In Dagger Hilt View Model 1.0.0-alpha01
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha01"
implementation 'com.google.dagger:hilt-android:2.28-alpha'
kapt 'androidx.hilt:hilt-compiler:1.0.0-alpha01'
kapt 'com.google.dagger:hilt-android-compiler:2.28-alpha'
我可以使用以下
class MyViewModel @ViewModelInject constructor(
private val repository: Repository,
@Assisted private val savedStateHandle: SavedStateHandle
) : ViewModel(), LifecycleObserver {
// Some codes...
}
但是,当我迁移到Dagger Hilt View Model 1.0.0-alpha03
However, when I migrate to Dagger Hilt View Model 1.0.0-alpha03
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
implementation 'com.google.dagger:hilt-android:2.31.2-alpha'
kapt 'androidx.hilt:hilt-compiler:1.0.0-alpha03'
kapt 'com.google.dagger:hilt-android-compiler:2.31.2-alpha'
我得到了警告
'Assisted' is deprecated. Deprecated in Java
'ViewModelInject' is deprecated. Deprecated in Java
'ViewModelInject' is deprecated. Deprecated in Java
'Assisted' is deprecated. Deprecated in Java
新的工作方式是什么?
推荐答案
在alpha03中,现在使用新的 @HiltViewModel
和常规的 @Inject
,如下所示./p>
In alpha03, Use the new @HiltViewModel
and the normal @Inject
now as shown below.
@HiltViewModel
class MyViewModel @Inject constructor(
private val repository: Repository,
private val savedStateHandle: SavedStateHandle
) : ViewModel(), LifecycleObserver {
// Some code
}
这篇关于不推荐使用Dagger Hilt“辅助"和"ViewModelInject".在Dagger Hilt视图模型1.0.0-alpha03中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!