我花了很长时间弄清楚如何设置 Dagger 依赖项来满足这个片段的本质。
我有一个控制器 WelcomeScreen(它扩展了 Path - 一个 Mortar/Flow 事物),它声明它注入了一个 ThingView。然后我注入一个 ThingView 的提供者,我的 ThingView 构造函数有一个带有 Activity 的 @Inject 注释,我在其他地方提供了它。
我最终仍然收到此错误:没有为成员/com .....view.ThingView 注册注入。您必须将其显式添加到您的模块之一中的“注入”选项中。
对我缺少什么的想法?
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);
}
}
更新:我还尝试添加以下对错误消息没有影响的内容:
@Module(addsTo = ApplicationModule.class, library = true)
public class ActivityModule {
@Provides
public ThreadPackView providesThreadPackView() {
return new ThreadPackView(activity);
}
}