@subcomponent.factory method is missing parameters for required modules or subcomponents

百般思念 提交于 2020-02-06 07:23:20

问题


I am injecting Presenter to BookDashboard(Activity) and BookDashboardPresenter class require an MvpView interface in it's constructor .

When i run

AppComponent

@Component(
    modules = [
        AndroidInjectionModule::class,
        ActivityBuilder::class
    ]
)
@Singleton
interface AppComponent : AndroidInjector<App> {

    @Component.Builder
    interface Builder {

        fun addContext(@BindsInstance context: Context): Builder
        fun addBookEngine(@BindsInstance bookEngineModule: BookEngineModule) :Builder
        fun build(): AppComponent
    }
}

ActivityBuilder.kt

@Module
abstract class ActivityBuilder {

    @ContributesAndroidInjector(modules = {BookEngineModule.class})
    public abstract BookDashboard bindBookDashboard();
}

BookEngineModule.kt

@Module
class BookEngineModule(val mvpView: BookDashboardContract.MvpView){

    @Provides
    fun providePresenter():BookDashboardContract.Presenter{
        return BookDashboardPresenter(mvpView)
    }
}

BookDashboardContract

interface BookDashboardContract {

  interface MvpView{
    fun displayBooks()
    fun showProgress()
    fun hideProgress()
  }

  interface Presenter{
    fun fetchedBooks()
  }
}

BookDashboardPresenter.kt

class BookDashboardPresenter @Inject constructor(val viewContract:BookDashboardContract.MvpView) : BookDashboardContract.Presenter{

    val bookInteractor = BookInteractor(this)

    override fun fetchedBooks() {
        bookInteractor.fetchDataFromServer()
        viewContract.displayBooks()
    }
}

BookDashboard -> Activity

class BookDashboard : DaggerAppCompatActivity(),BookDashboardContract.MvpView{

    @Inject
    lateinit var presenter: BookDashboardContract.Presenter

    override fun onCreate(savedInstanceState: Bundle?) {
        DaggerAppComponent.builder().addContext(this).
            addBookEngine(BookEngineModule(this)).build()
        super.onCreate(savedInstanceState)
        ///presenter.fetchedBooks()

    }

    override fun displayBooks() {
        Toast.makeText(this,"Books Displayed",Toast.LENGTH_LONG).show()
    }

    override fun showProgress() {}
    override fun hideProgress() {}
}

But when I build the project I am having below error

ActivityBuilder_BindBookDashboard.java:24: error: @Subcomponent.Factory method is missing parameters for required modules or subcomponents: [quiz.mania.trivia.mcq.question.di.BookEngineModule]
    interface Factory extends AndroidInjector.Factory<BookDashboard> {}

DaggerClass

@Module(subcomponents = ActivityBuilder_BindBookDashboard.BookDashboardSubcomponent.class)
public abstract class ActivityBuilder_BindBookDashboard {
  private ActivityBuilder_BindBookDashboard() {}

  @Binds
  @IntoMap
  @ClassKey(BookDashboard.class)
  abstract AndroidInjector.Factory<?> bindAndroidInjectorFactory(
      BookDashboardSubcomponent.Factory builder);

  @Subcomponent(modules = BookEngineModule.class)
  public interface BookDashboardSubcomponent extends AndroidInjector<BookDashboard> {
    @Subcomponent.Factory
    interface Factory extends AndroidInjector.Factory<BookDashboard> {}
  }
}

above class can't resolve BookEngineModule and BookDashboard

What am i missing ?

来源:https://stackoverflow.com/questions/60036880/subcomponent-factory-method-is-missing-parameters-for-required-modules-or-subco

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!