Class DIContainer

java.lang.Object
com.itextpdf.commons.utils.DIContainer

public class DIContainer extends Object
A simple dependency injection container.

The container is thread-safe.

  • Constructor Details

    • DIContainer

      public DIContainer()
      Creates a new instance of DIContainer.
  • Method Details

    • registerDefault

      public static void registerDefault (Class clazz, Supplier<Object> supplier)
      Registers a default instance for a class.
      Parameters:
      clazz - the class
      supplier - supplier of the instance
    • register

      public void register (Class clazz, Object inst)
      Registers an instance for a class.
      Parameters:
      clazz - the class
      inst - the instance
    • getInstance

      public  T getInstance (Class clazz)
      Gets an instance of a class.
      Type Parameters:
      T - the type of the class
      Parameters:
      clazz - the class
      Returns:
      the instance
    • isRegistered

      public boolean isRegistered (Class clazz)
      Checks if an instance is registered for a class. If the class is registered but the value is null, it will still return true.
      Parameters:
      clazz - the class
      Returns:
      true if an instance is registered, false otherwise