Class Sigewine

java.lang.Object
enterprises.iwakura.sigewine.Sigewine

public class Sigewine extends Object
Main entry point to the Sigewine Dependency Injection (DI) API.

This class provides functionality for scanning, registering, and injecting beans (classes or methods annotated with RomaritimeBean) into a dependency graph.

Usage:

  1. Create an instance of SigewineOptions to configure logging and other options.
  2. Instantiate Sigewine with the options.
  3. Use treatment(Class) or treatment(String) to scan packages for beans.
  4. Use syringe(Class) to inject dependencies into a class.
  • Field Details

    • sigewineOptions

      protected final SigewineOptions sigewineOptions
      Sigewine options.
    • beans

      protected final Map<String,Object> beans
      Map of beans registered in the DI container.
    • initializeLaterMethodBeans

      protected final List<Class<?>> initializeLaterMethodBeans
      List of classes that have method beans that need to be initialized later.
    • methodBeanDeclaringClassCache

      protected final Map<Class<?>,Object> methodBeanDeclaringClassCache
      Cache for method bean declaring classes.
  • Constructor Details

    • Sigewine

      public Sigewine(SigewineOptions sigewineOptions)
      Constructor for Sigewine.
      Parameters:
      sigewineOptions - Sigewine options
  • Method Details

    • treatment

      public void treatment(Class<?> clazz)
      Invokes treatment(String) with the package name of the class.
      Parameters:
      clazz - Class to get the package name from
    • treatment

      public void treatment(String packageName)
      Scans the package for beans and registers them.

      This method performs the following steps:

      1. Scans for methods annotated with RomaritimeBean and registers them as beans.
      2. Scans for classes annotated with RomaritimeBean and registers them as beans.
      3. Injects beans into fields of type TypedCollection.
      Parameters:
      packageName - The package name to scan.
    • syringe

      public <T> T syringe(Class<T> clazz)
      Injects dependencies into the specified class.

      This method resolves dependencies for the class and creates an instance with all dependencies injected.

      Type Parameters:
      T - The type of the class.
      Parameters:
      clazz - The class to inject dependencies into.
      Returns:
      An instance of the class with dependencies injected.
    • syringeInternal

      protected <T> T syringeInternal(Class<T> clazz, Function<Class<?>,Object> onUnknownBean)
      Injects dependencies into the class.
      Type Parameters:
      T - Type of the class
      Parameters:
      clazz - Class to inject dependencies into
      onUnknownBean - Function to call when a bean is not found. Should return a non-null bean or throw an exception.
      Returns:
      Instance of the class with dependencies injected
    • registerMethodBean

      protected void registerMethodBean(Method method)
      Registers a method bean.
      Parameters:
      method - Method to register
    • registerClassBean

      protected void registerClassBean(Class<?> clazz, boolean ignoreDuplicates)
      Registers a class bean.
      Parameters:
      clazz - Class to register
      ignoreDuplicates - Ignore duplicates
    • registerBeanWithInstance

      protected void registerBeanWithInstance(Class<?> clazz, String beanName, Object instance)
      Registers a bean with an instance. Checks if the bean is already registered.
      Parameters:
      clazz - Class of the bean
      beanName - Name of the bean
      instance - Instance of the bean
    • recursiveOnUnknownBean

      protected Object recursiveOnUnknownBean(Class<?> clazz)
      Recursively injects dependencies into the class.
      Parameters:
      clazz - Class to inject dependencies into
      Returns:
      Instance of the class with dependencies injected
    • getBeanName

      protected String getBeanName(RomaritimeBean romaritimeBean, String defaultName)
      Gets the bean name from the class.
      Parameters:
      romaritimeBean - Romaritime annotation
      defaultName - Default name to use if no name is specified
      Returns:
      Bean name
    • getAllBeansThatAreAssignableFrom

      protected Set<Object> getAllBeansThatAreAssignableFrom(Class<?> clazz)
      Gets all beans that are assignable from the specified class.
      Parameters:
      clazz - Class to check
      Returns:
      Set of beans that are assignable from the specified class