@Retention(value=RUNTIME)
@Target(value=TYPE)
@Documented
public static @interface Component.Builder
A builder is a type with setter methods for the modules, dependencies and bound instances required by the component and a single no-argument build method that creates a new component instance.
Components may have a single nested static abstract class
or interface
annotated with @Component.Builder
. If they do, then Dagger will generate a builder
class that implements that type. Note that a component with a @Component.Builder
may
not also have a @Component.Factory
.
Builder types must follow some rules:
void
, the builder
type or a supertype of the builder type.
abstract
module that has non-static
binding methods, unless Dagger can
instantiate that module with a visible no-argument constructor.
@BindsInstance
. These methods
bind the instance passed to them within the component. See @BindsInstance
for more information.
abstract
methods, but they are ignored as far as
validation and builder generation are concerned.
Component
with a Builder
:
@Component(modules = {BackendModule.class, FrontendModule.class})
interface MyComponent {
MyWidget myWidget();
@Component.Builder
interface Builder {
Builder backendModule(BackendModule bm);
Builder frontendModule(FrontendModule fm);
@BindsInstance
Builder foo(Foo foo);
MyComponent build();
}
}