Kodein 框架 - 属性 委托必须有一个 provideDelegate(...) 方法
Kodein Framework - property delegate must have a provideDelegate(...) method
我正在尝试构建具有以下架构的应用程序:LoginActivity -> MainActivity -> 在由 MainActivity 托管的片段中处理的所有其他内容。我也是第一次使用 Kodein 框架,在我的起始片段中出现以下错误:
Property delegate must have a 'provideDelegate(HomeFragment,
KProperty*>' method. None of the following functions is suitable.
provideDelegate(Context [highlighted in red], KProperty<>?) defined
in org.kodein.di.android.KodeinPropertyDelegateProvider Type
'KodeinPropertyDelegateProvider' has no method
'getValue(HomeFragment, KProperty<>)' and thus it cannot serve as a
delegate
到目前为止,这是我的代码:
class HomeFragment : Fragment(), KodeinAware {
override val kodein by kodein()
private val factory : MainViewModelFactory by instance()
private lateinit var viewModel: MainViewModel
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val binding : FragmentHomeBinding = FragmentHomeBinding.inflate(inflater, container, false)
viewModel = ViewModelProviders.of(this, factory).get(MainViewModel::class.java)
binding.viewModel = viewModel
return binding.root
}
}
我该如何解决这个问题?
谢谢:)
没关系,在 kodein 完成后添加类型声明...:)
在您的导入中更改
import org.kodein.di.android.kodein
至
import org.kodein.di.android.x.kodein
你可以这样做:
override val kodein:Kodein by kodein()
我正在尝试构建具有以下架构的应用程序:LoginActivity -> MainActivity -> 在由 MainActivity 托管的片段中处理的所有其他内容。我也是第一次使用 Kodein 框架,在我的起始片段中出现以下错误:
Property delegate must have a 'provideDelegate(HomeFragment, KProperty*>' method. None of the following functions is suitable. provideDelegate(Context [highlighted in red], KProperty<>?) defined in org.kodein.di.android.KodeinPropertyDelegateProvider Type 'KodeinPropertyDelegateProvider' has no method 'getValue(HomeFragment, KProperty<>)' and thus it cannot serve as a delegate
到目前为止,这是我的代码:
class HomeFragment : Fragment(), KodeinAware {
override val kodein by kodein()
private val factory : MainViewModelFactory by instance()
private lateinit var viewModel: MainViewModel
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val binding : FragmentHomeBinding = FragmentHomeBinding.inflate(inflater, container, false)
viewModel = ViewModelProviders.of(this, factory).get(MainViewModel::class.java)
binding.viewModel = viewModel
return binding.root
}
}
我该如何解决这个问题?
谢谢:)
没关系,在 kodein 完成后添加类型声明...:)
在您的导入中更改
import org.kodein.di.android.kodein
至
import org.kodein.di.android.x.kodein
你可以这样做:
override val kodein:Kodein by kodein()