Package org.apache.druid.guice
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 theoptionBinder()
method. Multiple different modules can calloptionBinder()
and all options will be reflected at injection time as long as equivalent interfaceKey
objects are passed into the various methods.
-
-
Constructor Summary
Constructors Constructor Description PolyBind()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods 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)
Deprecated.usecreateChoiceWithDefault(Binder, String, Key, String)
instead.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.
-
-
-
Method Detail
-
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 configuredproperty
- the property that will be checked to determine the implementation choiceinterfaceKey
- the interface that will be injected using this choicedefaultKey
- 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.usecreateChoiceWithDefault(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 configuredproperty
- the property that will be checked to determine the implementation choiceinterfaceKey
- the interface that will be injected using this choicedefaultPropertyValue
- 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 configuredinterfaceKey
- 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.
-
-