Interface IDependencyInjector<BindableType extends IBindable>

All Known Subinterfaces:
IDhApiEventInjector
All Known Implementing Classes:
ApiEventInjector, DependencyInjector

public interface IDependencyInjector<BindableType extends IBindable>
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    bind(Class<? extends BindableType> dependencyInterface, BindableType dependencyImplementation)
    Links the given implementation object to an interface, so it can be referenced later.
    boolean
    checkIfClassExtends(Class<?> classToTest, Class<?> extensionToLookFor)
    Checks if classToTest extends the given class.
    boolean
    checkIfClassImplements(Class<?> classToTest, Class<?> interfaceToLookFor)
    Checks if classToTest (or one of its ancestors) implements the given interface.
    void
    Removes all bound dependencies.
    <T extends BindableType>
    T
    get(Class<T> interfaceClass)
    Does not return incomplete dependencies.
    <T extends BindableType>
    T
    get(Class<T> interfaceClass, boolean allowIncompleteDependencies)
    Returns a dependency of type T if one has been bound.
    <T extends BindableType>
    ArrayList<T>
    getAll(Class<T> interfaceClass)
    Returns all dependencies of type T that have been bound.
    void
    Runs delayed setup for any dependencies that require it.
  • Method Details

    • bind

      void bind(Class<? extends BindableType> dependencyInterface, BindableType dependencyImplementation) throws IllegalStateException, IllegalArgumentException
      Links the given implementation object to an interface, so it can be referenced later.
      Parameters:
      dependencyInterface - The interface (or parent class) the implementation object should implement.
      dependencyImplementation - An object that implements the dependencyInterface interface.
      Throws:
      IllegalStateException - if the interface has already been bound and duplicates aren't allowed
      IllegalArgumentException - if the implementation object doesn't implement the interface
    • checkIfClassImplements

      boolean checkIfClassImplements(Class<?> classToTest, Class<?> interfaceToLookFor)
      Checks if classToTest (or one of its ancestors) implements the given interface.
    • checkIfClassExtends

      boolean checkIfClassExtends(Class<?> classToTest, Class<?> extensionToLookFor)
      Checks if classToTest extends the given class.
    • get

      <T extends BindableType> T get(Class<T> interfaceClass) throws ClassCastException
      Does not return incomplete dependencies.
      See get(Class, boolean) for full documentation.
      Throws:
      ClassCastException
      See Also:
    • getAll

      <T extends BindableType> ArrayList<T> getAll(Class<T> interfaceClass) throws ClassCastException
      Returns all dependencies of type T that have been bound.
      Returns an empty list if no dependencies have been bound.
      Type Parameters:
      T - class of the dependency (inferred from the objectClass parameter)
      Parameters:
      interfaceClass - Interface of the dependency
      Returns:
      the dependency of type T
      Throws:
      ClassCastException - If the dependency isn't able to be cast to type T. (this shouldn't normally happen, unless the bound object changed somehow)
    • get

      <T extends BindableType> T get(Class<T> interfaceClass, boolean allowIncompleteDependencies) throws ClassCastException
      Returns a dependency of type T if one has been bound.
      Returns null if a dependency hasn't been bound.

      If the handler allows duplicate bindings, this will return the first bound dependency.
      Type Parameters:
      T - class of the dependency (inferred from the interfaceClass parameter)
      Parameters:
      interfaceClass - Interface of the dependency
      allowIncompleteDependencies - If true this method will also return dependencies that haven't completed their delayed setup.
      Returns:
      the dependency of type T
      Throws:
      ClassCastException - If the dependency isn't able to be cast to type T. (this shouldn't normally happen, unless the bound object changed somehow)
    • clear

      void clear()
      Removes all bound dependencies.
    • runDelayedSetup

      void runDelayedSetup()
      Runs delayed setup for any dependencies that require it.