Class Injections
- java.lang.Object
-
- org.glassfish.jersey.internal.inject.Injections
-
public class Injections extends java.lang.ObjectInjection binding utility methods.
-
-
Constructor Summary
Constructors Constructor Description Injections()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static InjectionManagercreateInjectionManager()Creates aInjectionManagerwithout parent and initial binder.static InjectionManagercreateInjectionManager(java.lang.Object parent)Creates an unnamed, parentedInjectionManager.static InjectionManagercreateInjectionManager(Binder binder)Creates aInjectionManagerwith initial binder that is immediately registered.static <T> TgetOrCreate(InjectionManager injectionManager, java.lang.Class<T> clazz)Get the class by contract or create and inject a new instance.private static InjectionManagerFactorylookupInjectionManagerFactory()private static <T> java.util.Optional<T>lookupService(java.lang.Class<T> clazz)Look for a service of given type.
-
-
-
Method Detail
-
createInjectionManager
public static InjectionManager createInjectionManager()
Creates aInjectionManagerwithout parent and initial binder.- Returns:
- a injection manager with all the bindings.
-
createInjectionManager
public static InjectionManager createInjectionManager(Binder binder)
Creates aInjectionManagerwith initial binder that is immediately registered.- Parameters:
binder- custom thebinder.- Returns:
- a injection manager with all the bindings.
-
createInjectionManager
public static InjectionManager createInjectionManager(java.lang.Object parent)
Creates an unnamed, parentedInjectionManager. In case theparentinjection manager is not specified, the locator will not be parented.- Parameters:
parent- The parent of this injection manager. Services can be found in the parent (and all grand-parents). May benull. An underlying DI provider checks whether the parent is in a proper type.- Returns:
- an injection manager with all the bindings.
-
lookupInjectionManagerFactory
private static InjectionManagerFactory lookupInjectionManagerFactory()
-
lookupService
private static <T> java.util.Optional<T> lookupService(java.lang.Class<T> clazz)
Look for a service of given type. If more then one service is found the method sorts them are returns the one with highest priority.- Type Parameters:
T- type of service to look for.- Parameters:
clazz- type of service to look for.- Returns:
- instance of service with highest priority or
nullif service of given type cannot be found. - See Also:
Priority
-
getOrCreate
public static <T> T getOrCreate(InjectionManager injectionManager, java.lang.Class<T> clazz)
Get the class by contract or create and inject a new instance.- Type Parameters:
T- instance type.- Parameters:
injectionManager- DI injection manager.clazz- class of the instance to be provider.- Returns:
- instance of the class either provided as a service or created and injected by HK2.
-
-