[英]Dagger Android View Injection Error
I'm having a heck of a time figuring out how to set up Dagger dependencies to satisfy what is essentially this snippet. 我花了一点时间来弄清楚如何设置Dagger依赖项,以满足本质上是此代码段。
I have a controller, WelcomeScreen, (which extends Path - a Mortar/Flow thing), which states that it injects a ThingView. 我有一个控制器WelcomeScreen(它扩展了Path-一个砂浆/流动的东西),它声明它注入了ThingView。 I then inject a provider of ThingView and my ThingView constructor has an @Inject annotation with an Activity, which I supply elsewhere. 然后,我注入ThingView的提供程序,我的ThingView构造函数有一个带有Activity的@Inject批注,该批注在其他地方提供。
I still end up getting this error: No inject registered for members/com.....view.ThingView. 我仍然最终收到此错误:没有为成员/com.....view.ThingView注册任何注入。 You must explicitly add it to the 'injects' option in one of your modules. 您必须将其显式添加到模块之一的“注入”选项中。
Thoughts on what I'm missing? 对我想念的东西有什么想法?
public class WelcomeScreen extends Path {
@dagger.Module(
injects = {
ThingView.class,
},
addsTo = ActivityModule.class)
public class Module {
}
@Singleton
public static class Presenter extends ViewPresenter<WelcomeView> {
@Inject
public Presenter(
Provider<ThingView> thingViewProvider,) {
// This causes an error: No inject registered for members/com.....view.ThingView.
// You must explicitly add it to the 'injects' option in one of your modules.
thingViewProvider.get()
}
}
}
public class ThingView extends LinearLayout {
@Inject
public ThingView(Activity activity) {
super(activity);
init(activity);
}
// Note - this might not be used anywhere.
public ThingView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
private void init(Context context) {
ObjectGraphService.inject(context, this);
View view = View.inflate(context, R.layout.view_thread_pack, this);
ButterKnife.inject(view);
}
}
Update: I've also tried adding the below which has had no effect on the error message: 更新:我也尝试添加以下内容,该内容对错误消息没有影响:
@Module(addsTo = ApplicationModule.class, library = true)
public class ActivityModule {
@Provides
public ThreadPackView providesThreadPackView() {
return new ThreadPackView(activity);
}
}
Thats not quite how Mortar works. 那不是迫击炮如何工作的。 You cannot inject the view into the presenter. 您不能将视图注入到演示者中。 Instead you inject your presenter to your view. 相反,您可以将演示者注入视图。 Here's aa few samples I found that shows a similar setup to what you are doing https://github.com/Zhuinden/MortarFlowInitialDemo https://github.com/matthew-compton/NerdRoll 我发现了一些示例,这些示例显示了与您正在执行的操作类似的设置https://github.com/Zhuinden/MortarFlowInitialDemo https://github.com/matthew-compton/NerdRoll
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.