Class Injector


  • public class Injector
    extends java.lang.Object
    convenience class providing static methods to conveniently create injectors ( like org.junit.Assert )
    Author:
    Konstantin Pribluda
    • Constructor Summary

      Constructors 
      Constructor Description
      Injector()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static ComponentAdapter annotatedField​(java.lang.Object key, java.lang.Class<?> impl, Parameter[] parameters, ComponentMonitor componentMonitor, java.lang.Class<? extends java.lang.annotation.Annotation> injectionAnnotation, boolean useNames)
      Convenience method to create annotated field injector
      static ComponentAdapter annotatedMethod​(java.lang.Object key, java.lang.Class<?> impl, Parameter[] parameters, ComponentMonitor monitor, java.lang.Class<? extends java.lang.annotation.Annotation> injectionAnnotation, boolean useNames)
      convenience method to create annotated method injector
      static ComponentAdapter composite​(java.lang.Object componentKey, java.lang.Class<?> componentImplementation, Parameter[] parameters, ComponentMonitor monitor, boolean useNames, Injector... injectors)
      creates composite injector
      static ComponentAdapter constructor​(java.lang.Object componentKey, java.lang.Class<?> componentImplementation, Parameter... parameters)
      Constructor injector that uses no monitor and no lifecycle adapter.
      static ComponentAdapter constructor​(java.lang.Object componentKey, java.lang.Class componentImplementation, Parameter[] parameters, ComponentMonitor monitor, boolean useNames)
      Creates a ConstructorInjector
      static ComponentAdapter constructor​(java.lang.Object componentKey, java.lang.Class componentImplementation, Parameter[] parameters, ComponentMonitor monitor, boolean useNames, boolean rememberChosenCtor)
      Creates a ConstructorInjector
      static ComponentAdapter method​(java.lang.Object componentKey, java.lang.Class componentImplementation, Parameter[] parameters, ComponentMonitor monitor, java.lang.String methodName, boolean useNames)
      convenience method to create method injector
      static ComponentAdapter multi​(java.lang.Object componentKey, java.lang.Class componentImplementation, Parameter[] parameters, ComponentMonitor componentMonitor, java.lang.String setterPrefix, boolean useNames)
      convenience method to create multi component adapter
      static ComponentAdapter namedField​(java.lang.Object key, java.lang.Class<?> impl, Parameter[] parameters, ComponentMonitor componentMonitor, java.lang.String fieldNames)
      convenience method to create named field injector
      static ComponentAdapter setter​(java.lang.Object componentKey, java.lang.Class componentImplementation, Parameter[] parameters, ComponentMonitor monitor, java.lang.String prefix, boolean useNames)
      convenience method to create setter injector
      static ComponentAdapter typedField​(java.lang.Object key, java.lang.Class<?> impl, Parameter[] parameters, ComponentMonitor componentMonitor, java.lang.String classNames)
      conveniently create typed field injector
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Injector

        public Injector()
    • Method Detail

      • constructor

        public static ComponentAdapter constructor​(java.lang.Object componentKey,
                                                   java.lang.Class<?> componentImplementation,
                                                   Parameter... parameters)
        Constructor injector that uses no monitor and no lifecycle adapter. This is a more convenient constructor for use when instantiating a constructor injector directly.
        Parameters:
        componentKey - the search key for this implementation
        componentImplementation - the concrete implementation
        parameters - the parameters used for initialization
      • constructor

        public static ComponentAdapter constructor​(java.lang.Object componentKey,
                                                   java.lang.Class componentImplementation,
                                                   Parameter[] parameters,
                                                   ComponentMonitor monitor,
                                                   boolean useNames)
                                            throws AbstractInjector.NotConcreteRegistrationException
        Creates a ConstructorInjector
        Parameters:
        componentKey - the search key for this implementation
        componentImplementation - the concrete implementation
        parameters - the parameters to use for the initialization
        monitor - the component monitor used by this addAdapter
        useNames - use argument names when looking up dependencies
        Throws:
        AbstractInjector.NotConcreteRegistrationException - if the implementation is not a concrete class.
        java.lang.NullPointerException - if one of the parameters is null
      • constructor

        public static ComponentAdapter constructor​(java.lang.Object componentKey,
                                                   java.lang.Class componentImplementation,
                                                   Parameter[] parameters,
                                                   ComponentMonitor monitor,
                                                   boolean useNames,
                                                   boolean rememberChosenCtor)
                                            throws AbstractInjector.NotConcreteRegistrationException
        Creates a ConstructorInjector
        Parameters:
        componentKey - the search key for this implementation
        componentImplementation - the concrete implementation
        parameters - the parameters to use for the initialization
        monitor - the component monitor used by this addAdapter
        useNames - use argument names when looking up dependencies
        rememberChosenCtor - remember the chosen constructor (to speed up second/subsequent calls)
        Throws:
        AbstractInjector.NotConcreteRegistrationException - if the implementation is not a concrete class.
        java.lang.NullPointerException - if one of the parameters is null
      • annotatedField

        public static ComponentAdapter annotatedField​(java.lang.Object key,
                                                      java.lang.Class<?> impl,
                                                      Parameter[] parameters,
                                                      ComponentMonitor componentMonitor,
                                                      java.lang.Class<? extends java.lang.annotation.Annotation> injectionAnnotation,
                                                      boolean useNames)
        Convenience method to create annotated field injector
        Parameters:
        key -
        impl -
        parameters -
        componentMonitor -
        injectionAnnotation -
        useNames -
        Returns:
        annotated field injector instance.
      • annotatedMethod

        public static ComponentAdapter annotatedMethod​(java.lang.Object key,
                                                       java.lang.Class<?> impl,
                                                       Parameter[] parameters,
                                                       ComponentMonitor monitor,
                                                       java.lang.Class<? extends java.lang.annotation.Annotation> injectionAnnotation,
                                                       boolean useNames)
        convenience method to create annotated method injector
        Parameters:
        key -
        impl -
        parameters -
        monitor -
        injectionAnnotation -
        useNames -
        Returns:
        method injector instance.
      • composite

        public static ComponentAdapter composite​(java.lang.Object componentKey,
                                                 java.lang.Class<?> componentImplementation,
                                                 Parameter[] parameters,
                                                 ComponentMonitor monitor,
                                                 boolean useNames,
                                                 Injector... injectors)
        creates composite injector
        Parameters:
        componentKey -
        componentImplementation -
        parameters -
        monitor -
        useNames -
        injectors -
        Returns:
        composite injector instance.
      • multi

        public static ComponentAdapter multi​(java.lang.Object componentKey,
                                             java.lang.Class componentImplementation,
                                             Parameter[] parameters,
                                             ComponentMonitor componentMonitor,
                                             java.lang.String setterPrefix,
                                             boolean useNames)
        convenience method to create multi component adapter
        Parameters:
        componentKey -
        componentImplementation -
        parameters -
        componentMonitor -
        setterPrefix -
        useNames -
        Returns:
        MultiInjector component adapter instance.
      • namedField

        public static ComponentAdapter namedField​(java.lang.Object key,
                                                  java.lang.Class<?> impl,
                                                  Parameter[] parameters,
                                                  ComponentMonitor componentMonitor,
                                                  java.lang.String fieldNames)
        convenience method to create named field injector
        Parameters:
        key -
        impl -
        parameters -
        componentMonitor -
        fieldNames -
        Returns:
        named field component injector instance.
      • typedField

        public static ComponentAdapter typedField​(java.lang.Object key,
                                                  java.lang.Class<?> impl,
                                                  Parameter[] parameters,
                                                  ComponentMonitor componentMonitor,
                                                  java.lang.String classNames)
        conveniently create typed field injector
        Parameters:
        key -
        impl -
        parameters -
        componentMonitor -
        classNames -
        Returns:
        typed field injector instance.