Class ManagerRegistry
java.lang.Object
com.zetaplugins.zetacore.services.di.ManagerRegistry
A registry for managing and injecting manager instances.
-
Constructor Summary
ConstructorsConstructorDescriptionManagerRegistry(JavaPlugin plugin) Creates a new ManagerRegistry for the given plugin.ManagerRegistry(JavaPlugin plugin, boolean requireManagerAnnotation, String packagePrefix) Creates a new ManagerRegistry for the given plugin. -
Method Summary
Modifier and TypeMethodDescription<T> TgetOrCreate(Class<T> cls) Gets an existing instance of the specified class, or creates one if it doesn't exist.voidInitializes and registers all eagerly loaded singleton managers found in the specified package.voidinjectManagers(Object target) Injects manager instances into the fields of the target object.voidregisterInstance(Class<?> cls, Object instance) Registers an existing instance in the registry under a specific class.voidregisterInstance(Object instance) Registers an existing instance in the registry.
-
Constructor Details
-
ManagerRegistry
Creates a new ManagerRegistry for the given plugin. Doesn't require theManagerannotation on managed classes.- Parameters:
plugin- The main plugin instance.
-
ManagerRegistry
Creates a new ManagerRegistry for the given plugin.- Parameters:
plugin- The main plugin instance.requireManagerAnnotation- Whether to require theManagerannotation on managed classes.
-
-
Method Details
-
initializeEagerManagers
public void initializeEagerManagers()Initializes and registers all eagerly loaded singleton managers found in the specified package. -
registerInstance
Registers an existing instance in the registry.- Parameters:
instance- The instance to register.
-
registerInstance
Registers an existing instance in the registry under a specific class.- Parameters:
cls- The class to register the instance under.instance- The instance to register.
-
getOrCreate
Gets an existing instance of the specified class, or creates one if it doesn't exist.- Type Parameters:
T- The type of the instance.- Parameters:
cls- The class of the instance to get or create.- Returns:
- The existing or newly created instance.
-
injectManagers
Injects manager instances into the fields of the target object.- Parameters:
target- The target object to inject managers into.
-