Interface DependencyInjector

All Known Implementing Classes:
DefaultDependencyInjector

public interface DependencyInjector
Central registry for dependencies and producing methods. Registered dependencies will be injected with the corresponding values if present, else null.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    index(@NotNull Class<?> clazz, @NotNull String... packages)
    Scans the whole classpath for methods annotated with Produces.
    void
    inject(Object instance)
    Injects all registered dependencies with the corresponding value.
    void
    registerDependencies(@NotNull Class<?> clazz, @NotNull List<Field> fields)
    Registers fields inside a class as dependencies.
    void
    registerProvider(@NotNull Object provider)
    Takes an instance of a class and scans it for methods annotated with Produces.
  • Method Details

    • index

      void index(@NotNull @NotNull Class<?> clazz, @NotNull @NotNull String... packages)
      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 registerProvider(Object) if no new instance of the declaring class should be created.
      Parameters:
      clazz - a class of the classpath to scan
      packages - package(s) to exclusively scan
    • registerProvider

      void registerProvider(@NotNull @NotNull Object provider)
      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.
      Parameters:
      provider - instance of the class to scan
    • registerDependencies

      void registerDependencies(@NotNull @NotNull Class<?> clazz, @NotNull @NotNull List<Field> fields)
      Registers fields inside a class as dependencies.
      Parameters:
      clazz - the declaring class
      fields - the dependencies to register
    • inject

      void inject(Object instance)
      Injects all registered dependencies with the corresponding value. If no value is present null gets injected.