evant / kotlin-inject

Dependency injection lib for kotlin
Apache License 2.0
1.14k stars 51 forks source link

Add an Option to generate actual create functions #362

Closed eygraber closed 3 months ago

eygraber commented 4 months ago

Fixes #361

eygraber commented 4 months ago

@evant any thoughts on this?

eygraber commented 3 months ago

I added a processor to my project that generates actual functions that call the target create function - https://github.com/eygraber/immich-kmp/blob/e5aa43231926962dd23f228a55bcd49514e7cd2e/ksp/generate-actual-compiler/src/main/kotlin/app/immich/kmp/ksp/generate/actual/GenerateProcessorProvider.kt

The usage looks like:

@GenerateActual
internal expect fun MainHostComponent.Companion.createKmp(
  sessionComponent: ImmichSessionComponent,
  route: Route,
): MainHostComponent

which generates:

@GenerateActual
internal actual fun MainHostComponent.Companion.createKmp(
    sessionComponent: ImmichSessionComponent,
    route: Route
): MainHostComponent = MainHostComponent.Companion.create(sessionComponent, route)
evant commented 3 months ago

sorry taking a long time to reply, this really feels like a giant hack which makes me hesitant to do something about it. I do like your additional processor solution better than an extra flag though.

eygraber commented 3 months ago

I can make a new PR using the additional processor idea.

eygraber commented 3 months ago

Any thoughts on what the new annotation could be called? I used GenerateActual as a placeholder, but I don't think that's good to release.

eygraber commented 3 months ago

Closing because of https://github.com/evant/kotlin-inject/pull/370