Class DefaultDependencyInjector

java.lang.Object
com.github.kaktushose.jda.commands.dependency.DefaultDependencyInjector
All Implemented Interfaces:
DependencyInjector

public class DefaultDependencyInjector extends Object implements DependencyInjector
Default implementation of DependencyInjector.
See Also:
  • Constructor Details

    • DefaultDependencyInjector

      public DefaultDependencyInjector()
      Create a new DependencyInjector.
  • Method Details

    • index

      public void index(@NotNull @NotNull Class<?> clazz, @NotNull @NotNull String... packages)
      Description copied from interface: DependencyInjector
      Scans the whole classpath for methods annotated with Produces. If found, creates a new instance of the declaring class and will call the method to retrieve the object and register it as a dependency. If the method is declared as static, no instance will be created. Use DependencyInjector.registerProvider(Object) if no new instance of the declaring class should be created.
      Specified by:
      index in interface DependencyInjector
      Parameters:
      clazz - a class of the classpath to scan
      packages - package(s) to exclusively scan
    • registerProvider

      public void registerProvider(@NotNull @NotNull Object provider)
      Description copied from interface: DependencyInjector
      Takes an instance of a class and scans it for methods annotated with Produces. If found, will call the method to retrieve the object and register it as a dependency.
      Specified by:
      registerProvider in interface DependencyInjector
      Parameters:
      provider - instance of the class to scan
    • registerDependencies

      public void registerDependencies(@NotNull @NotNull Class<?> clazz, @NotNull @NotNull List<Field> fields)
      Description copied from interface: DependencyInjector
      Registers fields inside a class as dependencies.
      Specified by:
      registerDependencies in interface DependencyInjector
      Parameters:
      clazz - the declaring class
      fields - the dependencies to register
    • inject

      public void inject(Object instance)
      Description copied from interface: DependencyInjector
      Injects all registered dependencies with the corresponding value. If no value is present null gets injected.
      Specified by:
      inject in interface DependencyInjector