Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflect compiler not generating default builder class. #145

Open
Laimiux opened this issue Jul 17, 2019 · 6 comments
Open

Reflect compiler not generating default builder class. #145

Laimiux opened this issue Jul 17, 2019 · 6 comments
Labels
bug Something isn't working

Comments

@Laimiux
Copy link
Contributor

Laimiux commented Jul 17, 2019

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()
@JakeWharton
Copy link
Owner

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 JakeWharton added the bug Something isn't working label Jul 18, 2019
@rohandhruva
Copy link

rohandhruva commented Aug 14, 2019

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()
  }

@Laimiux
Copy link
Contributor Author

Laimiux commented Aug 15, 2019 via email

@GC-Xi
Copy link

GC-Xi commented Apr 9, 2021

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

@Laimiux
Copy link
Contributor Author

Laimiux commented Apr 9, 2021

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
}

@GC-Xi
Copy link

GC-Xi commented Apr 9, 2021

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants