Interface Injector


public interface Injector
  • Method Details

    • forConstructor

      <T> ConstructorInjector<T> forConstructor(Class<T> type)
      Create injector for the given type
      Type Parameters:
      T - type of class
      Parameters:
      type - the type to process
      Returns:
      constructor injector
    • forConstructor

      <T> ConstructorInjector<T> forConstructor(Constructor<T> constructor)
      Create injector for the given constructor
      Type Parameters:
      T - type of class
      Parameters:
      constructor - the constructor to process
      Returns:
      constructor injector
    • forFields

      <T> FieldsInjector<T> forFields(Class<T> type)
      Create injector for fields (and constructor)
      Type Parameters:
      T - type of class
      Parameters:
      type - the type to process
      Returns:
      fields injector
    • forFields

      <T> FieldsInjector<T> forFields(Constructor<T> constructor)
      Create injector for fields (and constructor)
      Type Parameters:
      T - type of class
      Parameters:
      constructor - the constructor to process
      Returns:
      fields injector
    • newInstance

      <T> T newInstance(Class<T> type, Object... injectorArgs) throws DependencyInjectionException
      Create a new instance of the specified type using Injector
      Type Parameters:
      T - the type
      Parameters:
      type - the class to instantiate
      Returns:
      a new instance
      Throws:
      DependencyInjectionException - if anything happened during the injection
    • newInstance

      <T> T newInstance(Constructor<T> constructor, Object... injectorArgs) throws DependencyInjectionException
      Create a new instance of the specified constructor using Injector
      Type Parameters:
      T - the type
      Parameters:
      constructor - the constructor to instantiate
      Returns:
      a new instance
      Throws:
      DependencyInjectionException - if anything happens during the injection
    • newInstanceWithFields

      <T> T newInstanceWithFields(Class<T> type, Object... injectorArgs) throws DependencyInjectionException
      Create a new instance of the specified type using Injector with support for field injection
      Type Parameters:
      T - type of class
      Parameters:
      type - the class to instantiate
      Returns:
      a new instance
      Throws:
      DependencyInjectionException - if anything happens during the injection
    • newInstanceWithFields

      <T> T newInstanceWithFields(Constructor<T> constructor, Object... injectorArgs) throws DependencyInjectionException
      Create a new instance of the specified constructor using Injector with support for field injection
      Type Parameters:
      T - type of class
      Parameters:
      constructor - the constructor to instantiate
      Returns:
      a new instance
      Throws:
      DependencyInjectionException - if anything happens during the injection
    • forMethod

      MethodInjector forMethod(Method method)
      Create injector for the given method
      Parameters:
      method - the method to process
      Returns:
      injector for the given method
    • forGeneratedMethod

      MethodInjector forGeneratedMethod(Method method) throws Exception
      Generate injector for the given method

      This method should be used only with di-codegen module or other MethodInjector implementation Otherwise, it will fall back to forMethod(Method) and performance could be degraded

      Parameters:
      method - the method to process (works only for public properties)
      Returns:
      injector for the given method
      Throws:
      Exception - if anything happens during the generation of method wrapper
    • invokeMethod

      @Nullable <T> T invokeMethod(Method method, @Nullable @Nullable Object instance, Object... injectorArgs) throws DependencyInjectionException
      Invoke the method using Injector
      Type Parameters:
      T - the return type
      Parameters:
      method - the method to invoke
      instance - the instance to use (nullable for static context)
      Returns:
      the return value
      Throws:
      DependencyInjectionException - if anything happens during execution of the method
    • invokeAnnotatedMethods

      void invokeAnnotatedMethods(Class<? extends Annotation> annotation, Object instance, Object... injectorArgs) throws DependencyInjectionException
      Invoke methods annotated with the given annotation
      Parameters:
      annotation - the annotation to look for
      instance - the instance to use
      Throws:
      DependencyInjectionException - if anything happens during execution of the methods
    • invokeParameter

      @Nullable <T> T invokeParameter(Parameter parameter, Object... injectorArgs) throws Exception
      Get value that would be used to inject the given parameter
      Type Parameters:
      T - type of expected value
      Parameters:
      parameter - the parameter for which the value will be returned
      Returns:
      the associated binding value
      Throws:
      Exception - if anything happens during invocation of the parameter
    • fork

      Injector fork(InjectorController controller)
      Create a fork of resources. The current resources will be used as a parent of a new instance.
      Parameters:
      controller - initializer for a new instance of resources
      Returns:
      a forked instance of resources
    • duplicate

      Injector duplicate(InjectorController controller)
      Duplicate (clone) resources
      Parameters:
      controller - initializer for a new instance of resources
      Returns:
      a duplicated instance of resources
    • getResources

      Resources getResources()
      Get resources of injector
      Returns:
      the resources