amzn / kotlin-inject-anvil

Extensions for the kotlin-inject dependency injection framework
Apache License 2.0
271 stars 8 forks source link

Class type should be picked by default when there is no super type #67

Closed kirillzh closed 3 weeks ago

kirillzh commented 3 weeks ago

Code:

@Inject
@ContributesBinding(AppScope::class)
class F8eHttpClientProvider(
  private val appId: AppId,
  private val appVersion: String,
  private val appVariant: AppVariant,
  private val platformInfoProvider: PlatformInfoProvider,
  private val datadogTracerPluginProvider: DatadogTracerPluginProvider,
  private val networkingDebugService: NetworkingDebugService,
  private val appInstallationDao: AppInstallationDao,
  private val countryCodeGuesser: CountryCodeGuesser,
) { // note there is no supertype

Error:

e: [ksp] /Users/zhukov/src/squareup/wallet/app/shared/f8e-client/impl/src/commonMain/kotlin/build/wallet/f8e/client/F8eHttpClientProvider.kt:32: The bound type could not be determined for F8eHttpClientProvider. There are no super types.
e: [ksp] java.lang.IllegalArgumentException: The bound type could not be determined for F8eHttpClientProvider. There are no super types.

Current fix is to explicitly use class type as the bound type:

@ContributesBinding(AppScope::class, boundType = F8eHttpClientProvider::class)
vRallev commented 3 weeks ago

You don't need to "contribute a binding" when there is no binding. This is working as intended. By adding the @Inject annotation you can inject F8eHttpClientProvider.