无法提供Dagger Component.Factory

时间:2020-02-19 19:57:11

标签: android dagger-2

我有一个Component为数据输入提供依赖项:

@Component(modules = [DataInputModule::class])
interface DataInputComponent {
    fun inject(activity: DataInputActivity)

    fun factory(): Factory

    @Component.Factory
    interface Factory {
        fun create(@BindsInstance activity: DataInputActivity, module: DataInputModule): DataInputComponent
    }
}

使用模块:

@Module
class DataInputModule(private val activity: DataInputActivity) {
    @Provides
    fun provideDataInputViewModel(repo: MyRepository, timestampProvider: TimestampProvider) =
        DefaultDataInputViewModel(repo, timestampProvider)

    @Provides
    fun provideTimestampProvider(): TimestampProvider = DefaultTimestampProvider()

    @Provides
    fun provideDateTimeDialogFactory(): DateTimeDialogFactory = DateTimeDialogFactory(activity)
}

我的应用程序的组件如下所示:

@Singleton
@Component(
    modules = [
        DataListModule::class
    ]
)
interface AppComponent : AndroidInjector<MyApplication> {
    @Component.Factory
    interface Factory {
        fun create(@BindsInstance app: MyApplication): AppComponent
    }
}

带有提供可信赖的Room数据库和存储库的模块。

尝试构建时出现以下错误:

D:\ Applications \ AndroidStudioProjects \ MyApp \ app \ build \ tmp \ kapt3 \ stubs \ debug \ com \ example \ myapp \ di \ component \ DataInputComponent.java:7: 错误:[Dagger / MissingBinding] com.example.myapp.di.component.DataInputComponent.Factory无法 无需@Provides注释的方法即可提供。公共摘要 接口DataInputComponent { ^ com.example.myapp.di.component.DataInputComponent.Factory在以下位置提供 com.example.myapp.di.component.DataInputComponent.factory()

我无法将@Provides添加到@Component,因为它不是模块。我在线上寻找文档,但没有发现有人“提供”注释并提供@Factory的示例。那么,什么原因可能导致此问题呢?

0 个答案:

没有答案