dagger-reflect icon indicating copy to clipboard operation
dagger-reflect copied to clipboard

Reflect compiler not generating default builder class.

Open Laimiux opened this issue 5 years ago • 6 comments

By default, dagger-compiler generates a default Builder class.

With setup such as this:

interface Host {
  fun myDependency(): MyDependency
}

@Component(dependencies = [Host::class])
interface MyFeatureComponent {
  fun feature(): MyFeature
}

there will be a generated method

DaggerMyFeatureComponent.builder().dependencies(myDependencies).build()

Laimiux avatar Jul 17 '19 21:07 Laimiux

We have a bunch of ignored functional tests for the same reason:

  // TODO reflect-compiler bug! Not generating builder method.
  exclude 'dagger/functional/builder/BuilderTest.java'
  exclude 'dagger/functional/cycle/DoubleCheckCycleTest.java'
  exclude 'dagger/functional/membersinject/MembersInjectionOrderingTest.java'
  exclude 'dagger/functional/nullables/NullabilityTest.java'
  exclude 'dagger/functional/MultibindingTest.java'
  exclude 'dagger/functional/NonComponentDependencyTest.java'

JakeWharton avatar Jul 18 '19 15:07 JakeWharton

Is there any workaround that can be used in the meantime for this? Can I provide the dependencies some other way?

My setup is roughly like this:

@Component(modules = [ FooModule::class ])
interface MyComponent { ... }

@Module
class FooModule(private val myInjectedActivity: BaseInjectedActivity) { ... }

abstract class BaseInjectedActivty {
  override fun onCreate(...) {
    val myComponent = DaggerMyComponent.builder().fooModule(FooModule(this)).build()
  }

rohandhruva avatar Aug 14 '19 23:08 rohandhruva

We declared @Component.Factory interface to workaround.

On Wed, Aug 14, 2019, 4:59 PM Rohan Dhruva [email protected] wrote:

Is there any workaround that can be used in the meantime for this? Can I provide the dependencies some other way?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/JakeWharton/dagger-reflect/issues/145?email_source=notifications&email_token=AAWYO27KTCPMSZOGEXMJXDLQESL5FA5CNFSM4IEUY4DKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4KOFXA#issuecomment-521462492, or mute the thread https://github.com/notifications/unsubscribe-auth/AAWYO23JZ7S324YHMR5FYOLQESL5FANCNFSM4IEUY4DA .

Laimiux avatar Aug 15 '19 00:08 Laimiux

Hi @Laimiux , would you share how you used @Component.Factory to work it around?

GC-Xi avatar Apr 09 '21 17:04 GC-Xi

Hi @Laimiux , would you share how you used @Component.Factory to work it around?

You have to explicitly declare a factory

@Component(dependencies = [Host::class])
interface MyFeatureComponent {
  @Component.Factory
  interface Factory {
    fun create(host: Host): MyFeatureComponent
  }

  fun feature(): MyFeature
}

Laimiux avatar Apr 09 '21 19:04 Laimiux

Thank you!

GC-Xi avatar Apr 09 '21 20:04 GC-Xi