我正在将Dagger2与子组件一起使用来注入依赖项。子组件声明如下:
@PerController
@Subcomponent(modules = {ControllerModule.class} )
public interface ControllerComponent {
// some inject methods
void inject( Fragment1 frg);
@Subcomponent.Builder
interface Builder {
@BindsInstance Builder mainActivity( MainActivity a );
ControllerComponent build();
}
}
ControllerModule的代码是:
@Module
public abstract class ControllerModule {
@PerController
@Binds
abstract DetailContract.Presenter detailPresenter(DetailPresenter p );
}
现在出于测试目的,我想用自定义实现替换原始ControllerModule,以实现此目标@ Subcomponent.Builder的修改方式如下:
interface Builder {
@BindsInstance Builder mainActivity( MainActivity a );
Builder controllerModule( ControllerModule module );
ControllerComponent build();
}
编译后发生错误:
错误:@ Subcomponent.Builder具有用于模块或子组件的设置器 不需要的
如何使用自定义ControllerModule实现创建ControllerComponent?