使用参数将 ViewModel 注入带有 Dagger 2 的 Fragment
Injecting ViewModel into the Fragment with Dagger 2, with parameters
我正在尝试使用单个工厂来创建带有构造函数参数的 ViewModel。
我遵循了@matejdro 在其中一个开放式匕首问题中的建议
https://github.com/google/dagger/issues/1273
但是注射不起作用
I"m getting an error:"错误:[Dagger/MissingBinding] kotlin.Lazy 不能在没有 @Provides 注释的方法的情况下提供。"
知道如何解决这个问题吗?
我将创建的项目上传到 github:https://github.com/davida5/daggerViewModelBestPractice
这很简单,您应该使用 dagger.Lazy
(包括导入)而不是 kotlin.Lazy
一旦问题得到解决,您将 运行 进入另一个问题; AFAIK 如果没有相应的合格提供者,您将无法使用合格的依赖项。您有一个合格的 UserManager
实例被注入 AccountsViewModel
。添加限定提供程序方法或从 AccountsViewModel
.
中删除限定
我正在尝试使用单个工厂来创建带有构造函数参数的 ViewModel。 我遵循了@matejdro 在其中一个开放式匕首问题中的建议 https://github.com/google/dagger/issues/1273
但是注射不起作用
I"m getting an error:"错误:[Dagger/MissingBinding] kotlin.Lazy 不能在没有 @Provides 注释的方法的情况下提供。"
知道如何解决这个问题吗? 我将创建的项目上传到 github:https://github.com/davida5/daggerViewModelBestPractice
这很简单,您应该使用 dagger.Lazy
(包括导入)而不是 kotlin.Lazy
一旦问题得到解决,您将 运行 进入另一个问题; AFAIK 如果没有相应的合格提供者,您将无法使用合格的依赖项。您有一个合格的 UserManager
实例被注入 AccountsViewModel
。添加限定提供程序方法或从 AccountsViewModel
.