Class PolyBind

java.lang.Object
org.apache.druid.guice.PolyBind

public class PolyBind extends Object
Provides the ability to create "polymorphic" bindings where the polymorphism is actually just making a decision based on a value in Properties.

The workflow is that you first create a choice by calling createChoice(). Then you create options using the binder returned by the optionBinder() method. Multiple different modules can call optionBinder() and all options will be reflected at injection time as long as equivalent interface Key objects are passed into the various methods.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> com.google.inject.binder.ScopedBindingBuilder
    createChoice(com.google.inject.Binder binder, String property, com.google.inject.Key<T> interfaceKey, com.google.inject.Key<? extends T> defaultKey)
    Sets up a "choice" for the injector to resolve at injection time.
    static <T> com.google.inject.binder.ScopedBindingBuilder
    createChoiceWithDefault(com.google.inject.Binder binder, String property, com.google.inject.Key<T> interfaceKey, com.google.inject.Key<? extends T> defaultKey, String defaultPropertyValue)
    static <T> com.google.inject.binder.ScopedBindingBuilder
    createChoiceWithDefault(com.google.inject.Binder binder, String property, com.google.inject.Key<T> interfaceKey, String defaultPropertyValue)
    Sets up a "choice" for the injector to resolve at injection time.
    static <T> com.google.inject.multibindings.MapBinder<String,T>
    optionBinder(com.google.inject.Binder binder, com.google.inject.Key<T> interfaceKey)
    Binds an option for a specific choice.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PolyBind

      public PolyBind()
  • Method Details

    • createChoice

      public static <T> com.google.inject.binder.ScopedBindingBuilder createChoice(com.google.inject.Binder binder, String property, com.google.inject.Key<T> interfaceKey, @Nullable com.google.inject.Key<? extends T> defaultKey)
      Sets up a "choice" for the injector to resolve at injection time.
      Type Parameters:
      T - interface type
      Parameters:
      binder - the binder for the injector that is being configured
      property - the property that will be checked to determine the implementation choice
      interfaceKey - the interface that will be injected using this choice
      defaultKey - the default instance to be injected if the property doesn't match a choice. Can be null
      Returns:
      A ScopedBindingBuilder so that scopes can be added to the binding, if required.
    • createChoiceWithDefault

      @Deprecated public static <T> com.google.inject.binder.ScopedBindingBuilder createChoiceWithDefault(com.google.inject.Binder binder, String property, com.google.inject.Key<T> interfaceKey, com.google.inject.Key<? extends T> defaultKey, String defaultPropertyValue)
      Deprecated.
      use createChoiceWithDefault(Binder, String, Key, String) instead. defaultKey argument is ignored.
    • createChoiceWithDefault

      public static <T> com.google.inject.binder.ScopedBindingBuilder createChoiceWithDefault(com.google.inject.Binder binder, String property, com.google.inject.Key<T> interfaceKey, String defaultPropertyValue)
      Sets up a "choice" for the injector to resolve at injection time.
      Type Parameters:
      T - interface type
      Parameters:
      binder - the binder for the injector that is being configured
      property - the property that will be checked to determine the implementation choice
      interfaceKey - the interface that will be injected using this choice
      defaultPropertyValue - the default property value to use if the property is not set.
      Returns:
      A ScopedBindingBuilder so that scopes can be added to the binding, if required.
    • optionBinder

      public static <T> com.google.inject.multibindings.MapBinder<String,T> optionBinder(com.google.inject.Binder binder, com.google.inject.Key<T> interfaceKey)
      Binds an option for a specific choice. The choice must already be registered on the injector for this to work.
      Type Parameters:
      T - interface type
      Parameters:
      binder - the binder for the injector that is being configured
      interfaceKey - the interface that will have an option added to it. This must equal the Key provided to createChoice
      Returns:
      A MapBinder that can be used to create the actual option bindings.