amzn / kotlin-inject-anvil

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

Issue with subcomponents #76

Closed joshafeinberg closed 1 week ago

joshafeinberg commented 2 weeks ago

https://github.com/joshafeinberg/kiaerror

From this slack thread: https://kotlinlang.slack.com/archives/C0255B8KX7W/p1731383702672619

Issues:

  1. In 0.0.5 I used a "trick" to inherit from AppComponentMerged in my common classes. However after https://github.com/amzn/kotlin-inject-anvil/pull/61 this doesn't work anymore
  2. If I remove the @Component annotation from AppComponent then I can no longer have this be internal. I explained a bit in the code why I want this internal but understand if this is something that can't be supported
  3. Even once removing internal, dependencies from my subcomponent no longer work in the main component
vRallev commented 2 weeks ago

For 1) This workaround is redundant with #61. Just remove the classes

For 2) I filed #77. This particular use case makes sense.

For 3) There is a bug:

From the sample, given:

@AppScope
@MergeComponent(AppScope::class)
abstract class AppComponent(
    @Component val clientComponent: ClientComponent,
)

The generated component looks like this:

@Origin(value = AppComponent::class)
@Component
@MergeComponent(
  scope = AppScope::class,
  exclude = arrayOf(),
)
@AppScope
public abstract class KotlinInjectAppComponent(
  clientComponent: ClientComponent,
) : AppComponent(clientComponent)

Note that the @Component annotation is not carried over, therefore the code is not compiling.