parth
01/01/2025, 7:01 PM@Provides
methods need to be wrapped in a @Component
, else they don’t get picked up.
e.g.
//in file network.kt
@Provides
fun provideOkhttpClient(): OkHttpClient {
return OkHttpClient.Builder().build()
}
this won’t work, it needs to be
@ContributesTo(AppScope::class) //k-i-anvil annotation
interface NetworkComponent {
@Provides fun okhttp(): OkHttpClient { ... }
}
FR: could be cool to allow @Provides
on toplevel functions without a Component wrapper. Or have something in the docs for Dagger converts that says “use @Component
like Dagger uses `@Module`”evant
01/03/2025, 12:39 AMparth
01/03/2025, 12:40 AMevant
01/03/2025, 12:43 AM@ContributesTo
in anvil might be able to be extended to make it workparth
01/03/2025, 12:44 AM@Inject
could be applied to top-level functions, so could @Provides
evant
01/03/2025, 12:49 AM@Provides
would require.