@Documented @Retention(value=RUNTIME) @Target(value=METHOD) @Beta public @interface BindsInstance
For example:
@Component.Builder
interface Builder {
@BindsInstance Builder foo(Foo foo);
@BindsInstance Builder bar( @Blue Bar bar);
...
}
will allow clients of this builder 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 methods may not be passed null arguments unless the parameter is
annotated with @Nullable; in that case, both null and non-null arguments may be passed to
the method.
@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.
Copyright © 2012���2017 The Dagger Authors. All rights reserved.