【问题标题】:Dagger2 can not provide dependancyDagger 2 无法提供依赖
【发布时间】:2018-07-08 15:51:08
【问题描述】:

我尝试在 Kotlin 中使用 Dagger2 但出现此错误

错误:[Dagger/MissingBinding] [com.syouth.tsarz.base.BaseComponent.getNavigationManager()] android.support.v4.app.FragmentManager 不能在没有 @Provides-annotated 方法。

我真的很困惑,因为我在我的模块中提供了 FragmentManager:

@Module
class BaseModule {

    @Provides
    @BaseScope
    fun provideFragmentManager(activity: FragmentActivity): FragmentManager = activity.supportFragmentManager

}

这是我的组件:

@Subcomponent(modules = [(BaseModule::class)])
@BaseScope
interface BaseComponent {

    fun getNavigationManager(): NavigationManager

    @Subcomponent.Builder
    interface Builder {

        @BindsInstance
        fun activity(activity: FragmentActivity): Builder

        fun build(): BaseComponent
    }
}

导航管理器是通过使用@Inject 构造函数和带有@BaseScope 注释的类来注入的

所以基本上我只是尝试通过一个应该完全没问题的组件来获得依赖。 我哪里错了?

【问题讨论】:

    标签: android dependency-injection dagger-2


    【解决方案1】:

    在范围定义中使用了错误的注释。

    【讨论】:

    • 虽然我很高兴你能找到解决方案,但我认为添加一些关于你的解决方案的细节(哪些范围?它们在哪里定义?你怎么知道?等)会帮助你答案给未来的读者更多的好处。干杯!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多