Class Multibinder.RealMultibinder<T>

java.lang.Object
org.elasticsearch.common.inject.multibindings.Multibinder<T>
org.elasticsearch.common.inject.multibindings.Multibinder.RealMultibinder<T>
All Implemented Interfaces:
Module, Provider<Set<T>>
Enclosing class:
Multibinder<T>

public static final class Multibinder.RealMultibinder<T> extends Multibinder<T> implements Module, Provider<Set<T>>
The actual multibinder plays several roles:

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.

  • Method Details

    • configure

      public void configure(Binder binder)
      Description copied from interface: Module
      Contributes bindings and other configurations for this module to binder.

      Do not invoke this method directly to install submodules. Instead use Binder.install(Module), which ensures that provider methods are discovered.

      Specified by:
      configure in interface Module
    • addBinding

      public LinkedBindingBuilder<T> addBinding()
    • initialize

      @Inject public void initialize(Injector injector)
      Invoked by Guice at Injector-creation time to prepare providers for each element in this set. At this time the set's size is known, but its contents are only evaluated when get() is invoked.
    • get

      public Set<T> get()
      Description copied from interface: Provider
      Provides an instance of T. Must never return null.
      Specified by:
      get in interface Provider<T>
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object