T - A generic type of binding objectpublic static class Genie.Binder<T> extends Object
A Binder is used in module configure method to define a custom binding.
| Constructor and Description |
|---|
Binder(Class<T> type)
Create a
Binder for specified class |
| Modifier and Type | Method and Description |
|---|---|
Genie.Binder<T> |
doNotFireEvent()
Turn off the
forceFireEvent flag. |
Genie.Binder<T> |
forceFireEvent()
Turn on
forceFireEvent flag. |
Genie.Binder<T> |
in(Class<? extends Annotation> scope)
Constraint the binder with a scope annotation class.
|
Genie.Binder<T> |
named(String name)
Constraint the binding with a name.
|
Genie.Binder<T> |
qualifiedWith(Annotation... qualifiers)
Add qualifier annotation constraints to this binder
|
Genie.Binder<T> |
qualifiedWith(Class<? extends Annotation>... qualifiers)
Add qualifier annotation constraints to this binder
|
void |
register(Genie genie)
Register this binder to
Genie |
Genie.Binder<T> |
to(Class<? extends T> impl)
Bind this
Binder to a specific implementation. |
Genie.Binder<T> |
to(Constructor<? extends T> constructor)
Bind this binder to a constructor
|
Genie.Binder<T> |
to(javax.inject.Provider<? extends T> provider)
Bind this
Binder to a provider. |
Genie.Binder<T> |
to(T instance)
Bind this
Binder to a specific instance |
Genie.Binder<T> |
toConstructor(Class<? extends T> implement,
Class<?>... args)
Bind this instance to a constructor specified by class and constructor arguments.
|
Genie.Binder<T> |
withAnnotation(Annotation... annotations)
Deprecated.
|
Genie.Binder<T> |
withAnnotation(Class<? extends Annotation>... annotations)
Deprecated.
|
public Genie.Binder<T> to(Class<? extends T> impl)
Bind this Binder to a specific implementation.
If there is another binding already specified then it will throw out an IllegalStateException
impl - the implementation classIllegalStateException - if another binding existspublic Genie.Binder<T> to(T instance)
Bind this Binder to a specific instance
If there is another binding already specified then it will throw out an IllegalStateException
instance - the instance to which the Binder is boundIllegalStateException - if another binding existspublic Genie.Binder<T> to(javax.inject.Provider<? extends T> provider)
Bind this Binder to a provider.
If there is another binding already specified then it will throw out an IllegalStateException
provider - the provider that provides the instance to which this binder is boundIllegalStateException - if another binding existspublic Genie.Binder<T> to(Constructor<? extends T> constructor)
Bind this binder to a constructor
If there is another binding already specified then it will throw out an IllegalStateException
constructor - the constructor that generate the instance to which this binder is boundIllegalStateException - if another binding existspublic Genie.Binder<T> toConstructor(Class<? extends T> implement, Class<?>... args)
Bind this instance to a constructor specified by class and constructor arguments.
This is a convenient method for constructor binding as the developer does not need to provides a Constructor instance
If no constructor found with the class and argument types then an InjectException will be thrown out
If there is another binding already specified then it will throw out an IllegalStateException
implement - the class of the target instanceargs - the constructor argument typesInjectException - if no constructor found by the specIllegalStateException - if another binding existspublic Genie.Binder<T> named(String name)
Constraint the binding with a name.
A name is usually specified via Named annotation when declaring an injection. When genie looking for a provider for a named injection, it will check if the supplied binding matches the name specified.
If there is a name already registered it will throw out an IllegalArgumentException
name - the name of the bindingBinder instanceIllegalArgumentException - if there is name already registeredpublic Genie.Binder<T> in(Class<? extends Annotation> scope)
Constraint the binder with a scope annotation class.
Once the constraint is added to this binder the binding will search for candidates within the scope constraint only
The scope annotation class must be tagged with Scope annotation. Otherwise a InjectException will be thrown out.
scope - the scope annotation classInjectException - if the scope class is not annotated with ScopeIllegalStateException - if there is already a scope annotation constraint put on this binderScope@Deprecated public Genie.Binder<T> withAnnotation(Class<? extends Annotation>... annotations)
Add annotation constraints to this binder.
Usually the annotation specified in the parameter should be a valid qualifiers
This method is deprecated. Please use qualifiedWith(Class[]) instead
annotations - an array of annotation classesQualifier@Deprecated public Genie.Binder<T> withAnnotation(Annotation... annotations)
Add annotation constraints to this binder.
Usually the type of the annotation specified in the parameter should be a valid qualifiers
This method is deprecated. Please use qualifiedWith(Annotation...) instead
annotations - an array of annotation classesQualifierpublic Genie.Binder<T> qualifiedWith(Class<? extends Annotation>... qualifiers)
Add qualifier annotation constraints to this binder
Each qualifier annotation type must be tagged with Qualifier annotation. Otherwise an InjectException will be thrown out
qualifiers - an array of qualifier annotation typesInjectException - if the any qualifier class is not tagged with QualifierQualifierpublic Genie.Binder<T> qualifiedWith(Annotation... qualifiers)
Add qualifier annotation constraints to this binder
The type of each qualifier annotation must be tagged with Qualifier annotation. Otherwise an InjectException will be thrown out
qualifiers - an array of qualifier annotationsInjectException - if the any qualifier’s class is not tagged with QualifierQualifierpublic Genie.Binder<T> forceFireEvent()
Turn on forceFireEvent flag.
Once force fire event flag is turned on, when it calls register(Genie) method the Genie.fireProviderRegisteredEvent(Class) method will be called
public Genie.Binder<T> doNotFireEvent()
Turn off the forceFireEvent flag.
If this flag is turned off, no Genie.fireProviderRegisteredEvent(Class) call will happen upon register(Genie) method is called
public void register(Genie genie)
Register this binder to Genie
genie - the dependency injectorCopyright © 2016–2018 OSGL (Open Source General Library). All rights reserved.