【发布时间】:2018-07-18 15:47:38
【问题描述】:
我想使用 Dagger 2 提供一个函数作为依赖项:
@Module
class DatabaseModule {
@Provides
@Singleton
fun provideDatabase(application: Application, betaFilter: (BetaFilterable) -> Boolean): Database {
return Database(application, BuildConfig.VERSION_CODE, betaFilter)
}
@Provides
@Suppress("ConstantConditionIf")
fun provideBetaFiler(): (BetaFilterable) -> Boolean {
return if (BuildConfig.FLAVOR_audience == "regular") {
{ it.betaOnly.not() }
} else {
{ true }
}
}
}
不幸的是,它似乎不起作用:
[dagger.android.AndroidInjector.inject(T)] kotlin.jvm.functions.Function1<?
super com.app.data.BetaFilterable,java.lang.Boolean>
cannot be provided without an @Provides-annotated method.
我在这里错过了什么?
【问题讨论】:
标签: android dependency-injection kotlin functional-programming dagger-2