public static final class Multibinder.RealMultibinder<T> extends Multibinder<T> implements Module, Provider<Set<T>>, HasDependencies
As a Multibinder, it acts as a factory for LinkedBindingBuilders for each of the set's elements. Each binding is given an annotation that identifies it as a part of this set.
As a Module, it installs the binding to the set itself. As a module, this implements equals() and hashcode() in order to trick Guice into executing its configure() method only once. That makes it so that multiple multibinders can be created for the same target collection, but only one is bound. Since the list of bindings is retrieved from the injector itself (and not the multibinder), each multibinder has access to all contributions from all multibinders.
As a Provider, this constructs the set instances.
We use a subclass to hide 'implements Module, Provider' from the public API.
Multibinder.RealMultibinder<T>
Modifier and Type | Method and Description |
---|---|
LinkedBindingBuilder<T> |
addBinding()
Returns a binding builder used to add a new element in the set.
|
void |
configure(Binder binder)
Contributes bindings and other configurations for this module to
binder . |
boolean |
equals(Object o) |
Set<T> |
get()
Provides an instance of
T . |
Set<Dependency<?>> |
getDependencies()
Returns the known dependencies for this type.
|
int |
hashCode() |
void |
initialize(Injector injector)
Invoked by Guice at Injector-creation time to prepare providers for each
element in this set.
|
String |
toString() |
newSetBinder, newSetBinder, newSetBinder, newSetBinder, newSetBinder, newSetBinder
public void configure(Binder binder)
Module
binder
.
Do not invoke this method directly to install submodules. Instead use
Binder.install(Module)
, which ensures that provider methods
are
discovered.
public LinkedBindingBuilder<T> addBinding()
Multibinder
It is an error to call this method without also calling one of the
to
methods on the returned binding builder.
Scoping elements independently is supported. Use the in
method
to specify a binding scope.
addBinding
in class Multibinder<T>
@Inject public void initialize(Injector injector)
public Set<T> get()
Provider
T
. Must never return null
.public Set<Dependency<?>> getDependencies()
HasDependencies
Injector
will be
included in the returned set.getDependencies
in interface HasDependencies
Copyright © 2009–2016. All rights reserved.