afollestad / ulfberht

🗡️ A small but powerful & opinionated DI library. Written in Kotlin, and powered by annotation processing.

Home Page:https://af.codes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve @Provides circular dependency detection

afollestad opened this issue · comments

Below, SomeClass<String, Boolean> includes OneImpl in its @Provides method. OneImpl injects SomeClass<String, Boolean> into its constructor.

@Module
interface MyModule1 {
  @Binds fun one(one: OneImpl): One

  @Binds fun two(two: TwoImpl): Two
}

@Module
abstract class MyModule2 {
  @Provides fun one(one: OneImpl): SomeClass<String, Boolean> = SomeClass("test", true)

  @Provides fun two(two: TwoImpl): SomeClass<Int, Long> = SomeClass(6, 10L)
}

interface One {
  fun doSomething()
}

class OneImpl(
  private val two: Two,
  private val idk: SomeClass<String, Boolean>
) : One {
  override fun doSomething() = two.doSomething()
}