Class Injections


  • public class Injections
    extends Object
    Injection binding utility methods.
    Author:
    Tom Beerbower, Marek Potociar
    • Constructor Detail

      • Injections

        public Injections()
    • Method Detail

      • createInjectionManager

        public static InjectionManager createInjectionManager()
        Creates an InjectionManager without parent and initial binder.
        Returns:
        an injection manager with all the bindings.
      • createInjectionManager

        public static InjectionManager createInjectionManager​(Binder binder)
        Creates a InjectionManager with initial binder that is immediately registered.
        Parameters:
        binder - custom the binder.
        Returns:
        an injection manager with all the bindings.
      • createInjectionManager

        public static InjectionManager createInjectionManager​(Object parent)
        Creates an unnamed, parented InjectionManager. In case the parent injection 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 be null. An underlying DI provider checks whether the parent is in a proper type.
        Returns:
        an injection manager with all the bindings.
      • getOrCreate

        public static <T> T getOrCreate​(InjectionManager injectionManager,
                                        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.