@Documented
@Retention(value=RUNTIME)
@Target(value={METHOD,PARAMETER})
@Beta
public @interface BindsInstance
For example:
@Component.Builder
interface Builder {
@BindsInstance Builder foo(Foo foo);
@BindsInstance Builder bar( @Blue Bar bar);
...
}
// or
@Component.Factory
interface Factory {
MyComponent newMyComponent(
@BindsInstance Foo foo,
@BindsInstance @Blue Bar bar);
}
will allow clients of the builder or factory to pass their own instances of Foo and
Bar, and those instances can be injected within the component as Foo or
@Blue Bar, respectively.
@BindsInstance arguments may not be null unless the parameter is annotated
with @Nullable.
For builders, @BindsInstance methods must be called before building the component,
unless their parameter is marked @Nullable, in which case the component will act as
though it was called with a null argument. Primitives, of course, may not be marked
@Nullable.
Binding an instance is equivalent to passing an instance to a module constructor and providing that instance, but is often more efficient. When possible, binding object instances should be preferred to using module instances.