Dagger2 not resolving dependency all the way

前端 未结 2 904
南笙
南笙 2021-01-26 02:56

I have a MainActivity which injects Presenter, presenter object injects interactor and interactor object injects APIHelper. All the providers of presenter, interactor and APIHel

2条回答
  •  生来不讨喜
    2021-01-26 03:29

    Change MainPresenterImpl & ListingInteractorImpl constructors to following and precede them with @Inject:

    
        @Inject
        public MainPresenterImpl(MainActivity activity, ListingInteractor interactor) {...}
    
        @Inject
        public ListingInteractorImpl(Context context, APIHelper helper) {...}
    
    

    Then in your module implementation:

    
        @Provides
        @Singleton
        public MainViewPresenter providesMainPresenter(ListingInteractor interactor){
            return new MainPresenterImpl(activity, interactor);
        }
    
        @Provides
        @Singleton
        ListingInteractor providesInteractor(APIHelper helper){
            return new ListingInteractorImpl(activity, helper);
        }
    
    
    

提交回复
热议问题