Package enterprises.iwakura.sigewine
Class Sigewine
java.lang.Object
enterprises.iwakura.sigewine.Sigewine
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:
- Create an instance of
SigewineOptionsto configure logging and other options. - Instantiate
Sigewinewith the options. - Use
treatment(Class)ortreatment(String)to scan packages for beans. - Use
syringe(Class)to inject dependencies into a class.
-
Field Summary
FieldsModifier and TypeFieldDescriptionMap of beans registered in the DI container.List of classes that have method beans that need to be initialized later.Cache for method bean declaring classes.protected final SigewineOptionsSigewine options. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetAllBeansThatAreAssignableFrom(Class<?> clazz) Gets all beans that are assignable from the specified class.protected StringgetBeanName(RomaritimeBean romaritimeBean, String defaultName) Gets the bean name from the class.protected ObjectrecursiveOnUnknownBean(Class<?> clazz) Recursively injects dependencies into the class.protected voidregisterBeanWithInstance(Class<?> clazz, String beanName, Object instance) Registers a bean with an instance.protected voidregisterClassBean(Class<?> clazz, boolean ignoreDuplicates) Registers a class bean.protected voidregisterMethodBean(Method method) Registers a method bean.<T> TInjects dependencies into the specified class.protected <T> TsyringeInternal(Class<T> clazz, Function<Class<?>, Object> onUnknownBean) Injects dependencies into the class.voidInvokestreatment(String)with the package name of the class.voidScans the package for beans and registers them.
-
Field Details
-
sigewineOptions
Sigewine options. -
beans
Map of beans registered in the DI container. -
initializeLaterMethodBeans
List of classes that have method beans that need to be initialized later. -
methodBeanDeclaringClassCache
Cache for method bean declaring classes.
-
-
Constructor Details
-
Sigewine
Constructor for Sigewine.- Parameters:
sigewineOptions- Sigewine options
-
-
Method Details
-
treatment
Invokestreatment(String)with the package name of the class.- Parameters:
clazz- Class to get the package name from
-
treatment
Scans the package for beans and registers them.This method performs the following steps:
- Scans for methods annotated with
RomaritimeBeanand registers them as beans. - Scans for classes annotated with
RomaritimeBeanand registers them as beans. - Injects beans into fields of type
TypedCollection.
- Parameters:
packageName- The package name to scan.
- Scans for methods annotated with
-
syringe
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
Injects dependencies into the class.- Type Parameters:
T- Type of the class- Parameters:
clazz- Class to inject dependencies intoonUnknownBean- 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
Registers a method bean.- Parameters:
method- Method to register
-
registerClassBean
Registers a class bean.- Parameters:
clazz- Class to registerignoreDuplicates- Ignore duplicates
-
registerBeanWithInstance
Registers a bean with an instance. Checks if the bean is already registered.- Parameters:
clazz- Class of the beanbeanName- Name of the beaninstance- Instance of the bean
-
recursiveOnUnknownBean
Recursively injects dependencies into the class.- Parameters:
clazz- Class to inject dependencies into- Returns:
- Instance of the class with dependencies injected
-
getBeanName
Gets the bean name from the class.- Parameters:
romaritimeBean- Romaritime annotationdefaultName- Default name to use if no name is specified- Returns:
- Bean name
-
getAllBeansThatAreAssignableFrom
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
-