google / dagger

A fast dependency injector for Android and Java.
https://dagger.dev
Apache License 2.0
17.45k stars 2.02k forks source link

[HILT] @DefineComponent.Factory #2674

Open FunkyMuse opened 3 years ago

FunkyMuse commented 3 years ago

We're having a

@DefineComponent.Builder

and we need to create a builder which

@DefineComponent.Builder
interface MyCustomComponentBuilder {
  fun fooSeedData(@BindsInstance foo: Foo): MyCustomComponentBuilder
  fun build(): MyCustomComponent
}

Instead as of like with Dagger2 we can have something like

@DefineComponent.Factory
interface MyCustomComponentFactory {
  fun fooSeedData(@BindsInstance foo: Foo): MyCustomComponent
}
Chang-Eric commented 3 years ago

Leaving this open as a feature request, but I'm not sure we really want to add this. While it isn't necessarily hard to do, it adds another way to do the same thing with only marginal additional benefit. Especially because Hilt attempts to hide component construction as much as possible (as opposed to Dagger where it is a central part of the API), I think it is reasonable to say that you might need to wrap the builder if you want to expose a different API surface.