没有@Provides注释的方法无法提供-Dagger

时间:2020-06-16 07:53:19

标签: android dagger-2 dagger

我像下面一样从dagger开始使用,我有多个Qualifiers

@Module(
    includes = [LoginDialogFragmentModule.LoginPresenterAPIViewAbstractModule::class,
        RemoteAPIDataModule::class,
        RemoteAPIDataModuleTS::class
    ]
)
public class LoginDialogFragmentModule {
    @LoginDialogFragmentScoped
    @Provides
    fun provideLoginPresenterAPI(
        courseView: LoginContract.LoginView,
        dataSourcesApi: DataSourcesApi
    ): LoginPresenter {
        return LoginPresenter(
            courseView,
            dataSourcesApi
        )
    }

    @LoginDialogFragmentScoped
    @Provides
    @LoginComposQualifiers
    fun provideCompositeDisposableLogin(): CompositeDisposable {
        return CompositeDisposable()
    }

    @LoginDialogFragmentScoped
    @Provides
    fun loginAPI(
        loginDialogFragment: LoginDialogFragment,
        @CommonComposQualifiers mCompositeCommonDisposable: CompositeDisposable,
        @LoginComposQualifiers mCompositeLoginDisposable: CompositeDisposable,
        @CommonApiQualifiers publicApi: PublicApi,
        @LoginApiQualifires publicApiTS: PublicApiTS
    ): DataSourcesApi {
        return DataSourcesApi(
            loginDialogFragment.context!!,
            mCompositeCommonDisposable,
            mCompositeLoginDisposable,
            publicApi,
            publicApiTS
        )
    }

    @Module
    interface LoginPresenterAPIViewAbstractModule {
        @LoginDialogFragmentScoped
        @Binds
        fun loginPresenterAPI(loginPresenter: LoginPresenter): LoginContract.iLoginPresenters

        @LoginDialogFragmentScoped
        @Binds
        fun loginView(loginDialogFragment: LoginDialogFragment): LoginContract.LoginView
    }
}

在我的片段中,就像波纹管一样:

@LoginDialogFragmentScoped
class LoginDialogFragment :
    DefaultLifecycleObserver,
    DaggerAppCompatDialogFragment(),
    LoginContract.LoginView {

@Inject
    @LoginComposQualifiers
    lateinit var mCompositeDisposable: CompositeDisposable

    @Inject
    lateinit var loginPresenter: LoginPresenter

    private lateinit var loginViewModel: LoginDialogViewModel

override fun onDestroy(owner: LifecycleOwner) {
        try {
            mCompositeDisposable.clear()
            mCompositeDisposable.dispose()
        } catch (ex: Exception) {

        }
    }

}

但是它让我听到以下错误:

error: [Dagger/MissingBinding] @yyy.yyy.di.qualifiers.LoginComposQualifiers io.reactivex.disposables.CompositeDisposable cannot be provided without an @Provides-annotated method.

0 个答案:

没有答案