Class TinyDI

  • All Implemented Interfaces:
    java.lang.Runnable

    public class TinyDI
    extends java.lang.Object
    implements java.lang.Runnable
    The context in which dependency injection will happen. This class performs classpath scanning, annotation processing, and dependency injection.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  TinyDI.Config
      TinyDI's configuration helper.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object componentFor​(java.lang.Class<?> componentClass)
      Returns instance of an already registered component, taking into account its instantiation scope.
      java.lang.Object componentFor​(java.lang.String componentName)
      Returns instance of an already registered component, taking into account its instantiation scope.
      static TinyDI.Config config()
      Provides builder class through which TinyDI can be configured and instantiated.
      protected java.lang.reflect.Constructor<?> constructorWithLocalClassLoader​(java.lang.reflect.Constructor<?> ctor)
      Returns a Constructor instace, that's been loaded with this component's class loader.
      ScopeDI instantiationStrategy​(java.lang.Class<?> componentClass)
      Returns the instantiation strategy recognized by TinyDI for a particular class.
      ScopeDI instantiationStrategy​(java.lang.Object instance)
      Returns the instantiation strategy used by TinyDI to create an instance of a particular object.
      protected java.lang.reflect.Method methodWithLocalClassLoader​(java.lang.reflect.Method method)
      Returns a Method instance, that's been loaded with this component's class loader.
      java.lang.Class<?> registeredComponentClass​(java.lang.String componentName)
      Returns the class definition of an already registered component.
      java.lang.String registeredComponentName​(java.lang.Class<?> componentClass)
      Returns the name of the first found registered component with a specific type.
      java.util.Set<java.lang.String> registeredComponentNames()
      Returns a collection of all the registered component names.
      protected void registerProxiedRecords​(java.util.List<Recorded> additionalRecords)
      Registers the passed @Recorded instances.
      protected java.lang.Class<?> reloadWithLocalClassLoader​(java.lang.Class<?> foreignClass)
      Returns a Class instance, that's been loaded with this component's class loader.
      void run()  
      • Methods inherited from class java.lang.Object

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

      • config

        public static TinyDI.Config config()
        Provides builder class through which TinyDI can be configured and instantiated.
        Returns:
        New instance of TinyDI.Config eventually producing new TinyDI context.
      • registerProxiedRecords

        protected void registerProxiedRecords​(java.util.List<Recorded> additionalRecords)
        Registers the passed @Recorded instances. Useful for programmatic DI.
        Parameters:
        additionalRecords - List of instances to be registered as participants in the DI process.
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
      • constructorWithLocalClassLoader

        protected java.lang.reflect.Constructor<?> constructorWithLocalClassLoader​(java.lang.reflect.Constructor<?> ctor)
        Returns a Constructor instace, that's been loaded with this component's class loader.
        Parameters:
        ctor - The original Constructor instance to reload
        Returns:
        A reloaded with the current class loader Constructor instance.
      • methodWithLocalClassLoader

        protected java.lang.reflect.Method methodWithLocalClassLoader​(java.lang.reflect.Method method)
        Returns a Method instance, that's been loaded with this component's class loader.
        Parameters:
        method - The original Method instance to reload
        Returns:
        A reloaded with the current class loader Method instance.
      • reloadWithLocalClassLoader

        protected java.lang.Class<?> reloadWithLocalClassLoader​(java.lang.Class<?> foreignClass)
        Returns a Class instance, that's been loaded with this component's class loader.
        Parameters:
        foreignClass - The original Class instance to reload
        Returns:
        A reloaded with the current class loader Class instance.
      • registeredComponentNames

        public java.util.Set<java.lang.String> registeredComponentNames()
        Returns a collection of all the registered component names.
        Returns:
        A set with the available component names.
      • registeredComponentClass

        public java.lang.Class<?> registeredComponentClass​(java.lang.String componentName)
        Returns the class definition of an already registered component.
        Parameters:
        componentName - The name the component was registered with.
        Returns:
        The registered Class instance or null if such is not found.
      • registeredComponentName

        public java.lang.String registeredComponentName​(java.lang.Class<?> componentClass)
        Returns the name of the first found registered component with a specific type.
        Parameters:
        componentClass - The component type to search for.
        Returns:
        The name the component or null.
      • instantiationStrategy

        public ScopeDI instantiationStrategy​(java.lang.Class<?> componentClass)
        Returns the instantiation strategy recognized by TinyDI for a particular class.
        Parameters:
        componentClass - The class to look into
        Returns:
        Any member of ScopeDI or null if the strategy cannot be determined.
      • instantiationStrategy

        public ScopeDI instantiationStrategy​(java.lang.Object instance)
        Returns the instantiation strategy used by TinyDI to create an instance of a particular object.
        Parameters:
        instance - The object to check.
        Returns:
        Any member of ScopeDI or null if the strategy cannot be determined.
      • componentFor

        public java.lang.Object componentFor​(java.lang.Class<?> componentClass)
        Returns instance of an already registered component, taking into account its instantiation scope.
        Parameters:
        componentClass - The class type of the component to search for and possibly instantiate
        Returns:
        A nonnull instance if a class match's been found, otherwise null.
      • componentFor

        public java.lang.Object componentFor​(java.lang.String componentName)
        Returns instance of an already registered component, taking into account its instantiation scope.
        Parameters:
        componentName - The name of the component to search for and possibly instantiate
        Returns:
        A nonnull instance if a name match's been found, otherwise null.