Dagger 2 static provider methods in kotlin
Although I think zsmb13's solution is better, I found another solution which works
@Module
class AModule {
@Module
companion object {
@JvmStatic
@Provides
fun providesA(): A = A()
}
// add other non-static provides here
}
However, note that there will be two generated classes: AModule_ProvidesAFactory
and AModule_Companion_ProvidesAFactory
rather than the one AModule_ProvidesAFactory
class for the case with an object instead of a class with a companion object
I can't test it right now, but I think this should work:
@Module
object AModule {
@JvmStatic
@Provides
fun providesA(): A = A()
}