[英]How to inject a Preseneter and View interface MVP dagger 2
Hi I am using dagger and unable to build project following is the error message I am getting 嗨,我使用匕首,无法建立项目,以下是我收到的错误消息
Error:(18, 10) error: [Dagger/MissingBinding]
com.headytest.android.category_listing.CategoryContract.CategoryView cannot
be provided without an @Provides-annotated method.
com.headytest.android.category_listing.CategoryContract.CategoryView is
injected at
com.headytest.android.category_listing.CategoryPresenterImpl.<init>
(categoryView)
com.headytest.android.category_listing.CategoryPresenterImpl is injected at
com.headytest.android.MainActivity.categoryPresenter
com.headytest.android.MainActivity is injected at
com.headytest.android.dagger_component.NetComponent.inject
(com.headytest.android. MainActivity)
Following is CategoryContract 以下是CategoryContract
public interface CategoryContract {
interface CategoryPresenter {
public void onStart();
public void onStop();
public void getCategoryLiast();
}
interface CategoryView {
public void onPreAPIRequest();
public void onAPISuccess();
public void onAPIError();
public void setCategoryList(Result result);
}
}
Following is Presenter 以下是主持人
public class CategoryPresenterImpl implements CategoryContract.CategoryPresenter {
CategoryContract.CategoryView categoryView;
Retrofit retrofit;
@Inject
public CategoryPresenterImpl(CategoryContract.CategoryView categoryView) {
this.categoryView = categoryView;
}
@Override
public void onStart() {
}
@Override
public void onStop() {
}
@Override
public void getCategoryLiast() {
}
}
Following is Module 以下是模块
@Module
public class CategoryContractModule {
private CategoryContract.CategoryView categoryView;
public CategoryContractModule(CategoryContract.CategoryView categoryView) {
this.categoryView = categoryView;
}
@Provides
@AScope
CategoryContract.CategoryView providesCategoryView() {
return this.categoryView;
}
@Provides
@AScope
CategoryPresenterImpl providesCategoryPresenter() {
return new CategoryPresenterImpl(categoryView);
}
}
NetComponent NetComponent
@Singleton
@Component(modules = {ApplicationModule.class, NetworkModule.class})
public interface NetComponent {
void inject(MainActivity activity);
}
CategoryPresenterComponent CategoryPresenterComponent
@AScope
@Component(dependencies = NetComponent.class, modules =
{CategoryContractModule.class})
public interface CategoryPresenterComponent {
void inject(MainActivity activity);
}
Inject code 注入代码
DaggerCategoryPresenterComponent.builder()
.netComponent(((App) getApplicationContext()).getNetComponent())
.categoryContractModule(new CategoryContractModule(this))
.build()
.inject(this);
I am providing view with Provides in module still I am getting error message Any idea why? 我仍在模块中提供“提供”视图,但仍收到错误消息任何想法为什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.