Class Injector

java.lang.Object
io.github.cjstehno.testthings.inject.Injector

public final class Injector extends Object
The entry point for the injection framework, providing a simple configurable means of injecting values into an instance via reflection.
  • Constructor Details

    • Injector

      public Injector()
  • Method Details

    • injector

      public static Injector injector(Consumer<Injections> config)
      Creates an injector with the provided configured injections.
      Parameters:
      config - the configured injections
      Returns:
      the configured injector
    • injector

      public static Injector injector(Injections injections)
      Creates a new Injector with the provided injections configured.
      Parameters:
      injections - the injections
      Returns:
      the injector
    • inject

      public static <T> T inject(T instance, Consumer<Injections> config) throws ReflectiveOperationException
      Applies the configured injections on the object instance.
      Type Parameters:
      T - the type of target instance
      Parameters:
      instance - the object instance
      config - the configured injections
      Returns:
      the instance of the object populated with the injected values
      Throws:
      ReflectiveOperationException - if there is a problem with the reflection operations
    • inject

      public <T> T inject(T instance) throws ReflectiveOperationException
      Injects the configured injections into the provided object instance.
      Type Parameters:
      T - the type of the target instance
      Parameters:
      instance - the object instance
      Returns:
      the instance of the object populated with the injected values
      Throws:
      ReflectiveOperationException - if there is a problem with the reflection operations