Interface InjectionManager
- All Known Implementing Classes:
CdiSeInjectionManager,DelayedHk2InjectionManager,ImmediateHk2InjectionManager
Lifecycle methods should be called in this order:
completeRegistration()- notifies that Jersey bootstrap has been finished and DI provider should be ready for a runtime.shutdown()- Jersey application has been closed and DI provider should make needed cleaning steps.
All getInstance methods can be called after completeRegistration() method has been called because at this all
components are bound to injection manager and ready for getting.
In turn, shutdown() method stops the possibility to use these methods and closes InjectionManager.
- Author:
- Petr Bouda
-
Method Summary
Modifier and TypeMethodDescriptionvoidCompletesInjectionManagerand the underlying DI provider.<T> TCreates an object with the given class.<T> TcreateAndInitialize(Class<T> createMe) Creates, injects and post-constructs an object with the given class.createForeignDescriptor(Binding binding) Creates and registers the descriptor in the underlying DI provider and returnsForeignDescriptorthat is specific descriptor for the underlying DI provider.<T> List<T>getAllInstances(Type contractOrImpl) Gets all services from this injection manager that implement this contract or have this implementation.<T> List<ServiceHolder<T>>getAllServiceHolders(Class<T> contractOrImpl, Annotation... qualifiers) Gets all services from this injection manager that implements this contract or has this implementation along with information about the service which can be kept byServiceHolder.<T> TgetInstance(Class<T> contractOrImpl) Gets the best service from this injection manager that implements this contract or has this implementation.<T> TgetInstance(Class<T> contractOrImpl, Annotation... qualifiers) Gets the best service from this injection manager that implements this contract or has this implementation.<T> TgetInstance(Class<T> contractOrImpl, String classAnalyzer) Gets the best service from this injection manager that implements this contract or has this implementation.<T> TgetInstance(Type contractOrImpl) Gets the best service from this injection manager that implements this contract or has this implementation.getInstance(ForeignDescriptor foreignDescriptor) Gets the service instance according toForeignDescriptorwhich is specific to the underlying DI provider.default RuntimeTypeGet RuntimeType of the InjectionManager.voidAnalyzes the given object and inject into its fields and methods.voidThis will analyze the given object and inject into its fields and methods.booleanisRegistrable(Class<?> clazz) Tests whether the providedclazzcan be registered by the implementation of theInjectionManager.booleanvoidpreDestroy(Object preDestroyMe) Analyzes the given object and call the preDestroy method.voidRegisters a collection of beans represented using fields in the provided descriptors.voidRegisters a provider.voidRegisters beans which are included inBinder.voidRegisters one bean represented using fields in the provided descriptor.voidshutdown()Shuts down the entireInjectionManagerand the underlying DI provider.
-
Method Details
-
completeRegistration
void completeRegistration()CompletesInjectionManagerand the underlying DI provider. All registered components are bound to injection manager and after an invocation of this method all components are available using e.g.getInstance(Class). -
shutdown
void shutdown()Shuts down the entireInjectionManagerand the underlying DI provider.Shutdown phase is dedicated to make some final cleaning steps regarding underlying DI provider.
-
isShutdown
boolean isShutdown()- Returns:
- Whether the
InjectionManagerhas been shutdown.
-
register
Registers one bean represented using fields in the provided descriptor. The final bean can be direct bean or factory object which will create the bean at the time of injection.InjectionManageris able to register a bean represented by a class or direct instance.- Parameters:
binding- one descriptor.- See Also:
-
register
Registers a collection of beans represented using fields in the provided descriptors. The final bean can be direct bean or factory object which will create the bean at the time of injection.InjectionManageris able to register a bean represented by a class or direct instance.- Parameters:
descriptors- collection of descriptors.- See Also:
-
register
Registers beans which are included inBinder.Bindercan contain all descriptors extendingBindingor other binders which are installed together in tree-structure. This method will get all descriptors bound in the given binder and register them in the order how the binders are installed together. In the tree structure, the deeper on the left side will be processed first.- Parameters:
binder- collection of descriptors.- See Also:
-
register
Registers a provider. An implementation of theInjectionManagershould test whether the type of the object can be registered using the methodisRegistrable(Class). Then a caller has an certainty that the instance of the tested class can be registered inInjectionManager. IfInjectionManageris not able to register the provider thenIllegalArgumentExceptionis thrown.- Parameters:
provider- object that can be registered inInjectionManager.- Throws:
IllegalArgumentException- provider cannot be registered.
-
isRegistrable
Tests whether the providedclazzcan be registered by the implementation of theInjectionManager.- Parameters:
clazz- type that is tested whether is registrable by the implementation ofInjectionManager.- Returns:
trueif theInjectionManageris able to register this type.
-
create
Creates an object with the given class.The object created is not managed by the injection manager.
- Parameters:
createMe- The non-null class to create this object from;- Returns:
- An instance of the object that has been created.
- Since:
- 2.35
-
createAndInitialize
Creates, injects and post-constructs an object with the given class. This is equivalent to calling thecreate-classmethod followed by theinject-classmethod followed by thepost-constructmethod.The object created is not managed by the injection manager.
- Parameters:
createMe- The non-null class to create this object from;- Returns:
- An instance of the object that has been created, injected and post constructed.
-
getAllServiceHolders
Gets all services from this injection manager that implements this contract or has this implementation along with information about the service which can be kept byServiceHolder.- Type Parameters:
T- Instance type.- Parameters:
contractOrImpl- May not be null, and is the contract or concrete implementation to get the best instance of.qualifiers- The set of qualifiers that must match this service definition.- Returns:
- An instance of the contract or impl along with other information. May return null if there is no provider that provides the given implementation or contract.
-
getInstance
Gets the best service from this injection manager that implements this contract or has this implementation.Use this method only if other information is not needed otherwise use, otherwise use
getAllServiceHolders(Class, Annotation...).- Type Parameters:
T- Instance type.- Parameters:
contractOrImpl- May not be null, and is the contract or concrete implementation to get the best instance of.qualifiers- The set of qualifiers that must match this service definition.- Returns:
- An instance of the contract or impl. May return null if there is no provider that provides the given implementation or contract.
-
getInstance
Gets the best service from this injection manager that implements this contract or has this implementation.Use this method only if other information is not needed otherwise use, otherwise use
getAllServiceHolders(Class, Annotation...).- Type Parameters:
T- Instance type.- Parameters:
contractOrImpl- May not be null, and is the contract or concrete implementation to get the best instance of.classAnalyzer- -------- Returns:
- An instance of the contract or impl. May return null if there is no provider that provides the given implementation or contract.
-
getInstance
Gets the best service from this injection manager that implements this contract or has this implementation.Use this method only if other information is not needed otherwise use, otherwise use
getAllServiceHolders(Class, Annotation...).- Type Parameters:
T- Instance type.- Parameters:
contractOrImpl- May not be null, and is the contract or concrete implementation to get the best instance of.- Returns:
- An instance of the contract or impl. May return null if there is no provider that provides the given implementation or contract.
-
getInstance
Gets the best service from this injection manager that implements this contract or has this implementation.Use this method only if other information is not needed otherwise use, otherwise use
getAllServiceHolders(Class, Annotation...).- Type Parameters:
T- Instance type.- Parameters:
contractOrImpl- May not be null, and is the contract or concrete implementation to get the best instance of.- Returns:
- An instance of the contract or impl. May return null if there is no provider that provides the given implementation or contract.
-
getInstance
Gets the service instance according toForeignDescriptorwhich is specific to the underlying DI provider.- Parameters:
foreignDescriptor- DI specific descriptor.- Returns:
- service instance according to foreign descriptor.
-
createForeignDescriptor
Creates and registers the descriptor in the underlying DI provider and returnsForeignDescriptorthat is specific descriptor for the underlying DI provider.- Parameters:
binding- jersey descriptor.- Returns:
- specific foreign descriptor of the underlying DI provider.
-
getAllInstances
Gets all services from this injection manager that implement this contract or have this implementation.Use this method only if other information is not needed otherwise use, otherwise use
getAllServiceHolders(Class, Annotation...).- Type Parameters:
T- Instance type.- Parameters:
contractOrImpl- May not be null, and is the contract or concrete implementation to get the best instance of.- Returns:
- A list of services implementing this contract or concrete implementation. May not return null, but may return an empty list
-
inject
Analyzes the given object and inject into its fields and methods. The object injected in this way will not be managed by HK2- Parameters:
injectMe- The object to be analyzed and injected into
-
inject
This will analyze the given object and inject into its fields and methods. The object injected in this way will not be managed by HK2- Parameters:
injectMe- The object to be analyzed and injected into
-
preDestroy
Analyzes the given object and call the preDestroy method. The object given will not be managed by bean manager.- Parameters:
preDestroyMe- The object to preDestroy
-
getRuntimeType
Get RuntimeType of the InjectionManager.- Returns:
- the runtimeType
-