如何注入 Preseneter 和视图界面 MVP 匕首 2.



嗨,我正在使用dagger,无法构建项目 以下是我收到的错误消息

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)

以下是类别合同

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);
}
}

以下是演示者

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() {
}
}

以下是模块

@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);
}
}

网络组件

@Singleton
@Component(modules = {ApplicationModule.class, NetworkModule.class})
public interface NetComponent {
void inject(MainActivity activity);

}

类别演示器组件

@AScope
@Component(dependencies = NetComponent.class, modules = 
{CategoryContractModule.class})
public interface CategoryPresenterComponent {
void inject(MainActivity activity);
}

注入代码

DaggerCategoryPresenterComponent.builder()
.netComponent(((App) getApplicationContext()).getNetComponent())
.categoryContractModule(new CategoryContractModule(this))
.build()
.inject(this);

我正在提供带有模块的视图,但我仍然收到错误消息 知道为什么吗?

NetworkComponent中删除void inject(MainActivity activity)将解决此问题。在此处查看详细答案。

最新更新