public abstract class AbstractBinder extends java.lang.Object implements Binder
Binder
interface dedicated to keep some level of code compatibility between previous HK2
implementation and new DI SPI.
Currently, there are supported only bind method and more complicated method where HK2 interfaces are required were omitted.
Modifier and Type | Field and Description |
---|---|
private boolean |
configured |
private InjectionManager |
injectionManager |
private java.util.List<AbstractBinder> |
installed |
private java.util.List<Binding> |
internalBindings |
Constructor and Description |
---|
AbstractBinder() |
Modifier and Type | Method and Description |
---|---|
Binding |
bind(Binding binding)
Binds the provided binding and return the same instance.
|
<T> ClassBinding<T> |
bind(java.lang.Class<T> serviceType)
Start building a new class-based service binding.
|
<T> InstanceBinding<T> |
bind(T service)
Start building a new instance-based service binding.
|
<T extends InjectionResolver> |
bind(T resolver)
Start building a new injection resolver binding.
|
<T> ClassBinding<T> |
bindAsContract(java.lang.Class<T> serviceType)
Start building a new class-based service binding.
|
<T> ClassBinding<T> |
bindAsContract(javax.ws.rs.core.GenericType<T> serviceType)
Start building a new generic type-based service binding.
|
ClassBinding<java.lang.Object> |
bindAsContract(java.lang.reflect.Type serviceType)
Start building a new generic type-based service binding.
|
<T> SupplierClassBinding<T> |
bindFactory(java.lang.Class<? extends java.util.function.Supplier<T>> supplierType)
Start building a new supplier class-based service binding.
|
<T> SupplierClassBinding<T> |
bindFactory(java.lang.Class<? extends java.util.function.Supplier<T>> supplierType,
java.lang.Class<? extends java.lang.annotation.Annotation> supplierScope)
Start building a new supplier class-based service binding.
|
<T> SupplierInstanceBinding<T> |
bindFactory(java.util.function.Supplier<T> factory)
Start building a new supplier instance-based service binding.
|
protected abstract void |
configure()
Implement to provide binding definitions using the exposed binding methods.
|
protected <T> javax.inject.Provider<T> |
createManagedInstanceProvider(java.lang.Class<T> clazz)
Creates a new instance of
Provider which is able to retrieve a managed instance registered in
InjectionManager . |
java.util.Collection<Binding> |
getBindings()
Gets a collection of descriptors registered in this jersey binder.
|
void |
install(AbstractBinder... binders)
Adds all binding definitions from the binders to the binding configuration.
|
private void |
invokeConfigure() |
(package private) void |
setInjectionManager(InjectionManager injectionManager)
Sets
InjectionManager to be able to create instance providers using the injection manager. |
private java.util.List<Binding> internalBindings
private java.util.List<AbstractBinder> installed
private InjectionManager injectionManager
private boolean configured
protected abstract void configure()
void setInjectionManager(InjectionManager injectionManager)
InjectionManager
to be able to create instance providers using the injection manager. InjectionManager
should be called before the invocation of configure()
, otherwise immediate invocation Provider.get()
returnsinjectionManager
- injection manager to create a provider.protected final <T> javax.inject.Provider<T> createManagedInstanceProvider(java.lang.Class<T> clazz)
Provider
which is able to retrieve a managed instance registered in
InjectionManager
. If InjectionManager
is null
at the time of calling Provider.get()
then
IllegalStateException
is thrown.T
- type of the managed instance returned using provider.clazz
- class of managed instance.public <T> ClassBinding<T> bind(java.lang.Class<T> serviceType)
Does NOT bind the service type itself as a contract type.
T
- service type.serviceType
- service class.public Binding bind(Binding binding)
binding
- binding.public <T> ClassBinding<T> bindAsContract(java.lang.Class<T> serviceType)
Binds the service type itself as a contract type.
T
- service type.serviceType
- service class.public <T> ClassBinding<T> bindAsContract(javax.ws.rs.core.GenericType<T> serviceType)
Binds the generic service type itself as a contract type.
T
- service type.serviceType
- generic service type information.public ClassBinding<java.lang.Object> bindAsContract(java.lang.reflect.Type serviceType)
Binds the generic service type itself as a contract type.
serviceType
- generic service type information.public <T> InstanceBinding<T> bind(T service)
singleton-scoped
.
Does NOT bind the service type itself as a contract type.
T
- service type.service
- service instance.public <T> SupplierClassBinding<T> bindFactory(java.lang.Class<? extends java.util.function.Supplier<T>> supplierType, java.lang.Class<? extends java.lang.annotation.Annotation> supplierScope)
T
- service type.supplierType
- service supplier class.supplierScope
- factory scope.public <T> SupplierClassBinding<T> bindFactory(java.lang.Class<? extends java.util.function.Supplier<T>> supplierType)
The supplier itself is bound in a per-lookup scope.
T
- service type.supplierType
- service supplier class.public <T> SupplierInstanceBinding<T> bindFactory(java.util.function.Supplier<T> factory)
T
- service type.factory
- service instance.public <T extends InjectionResolver> InjectionResolverBinding<T> bind(T resolver)
singleton-scoped
.
There is no need to provide any additional information. Other method on Binding
will be ignored.
T
- type of the injection resolver.resolver
- injection resolver instance.public final void install(AbstractBinder... binders)
binders
- binders whose binding definitions should be configured.public java.util.Collection<Binding> getBindings()
Binder
getBindings
in interface Binder
private void invokeConfigure()