Class ManagerRegistry

java.lang.Object
com.zetaplugins.zetacore.services.di.ManagerRegistry

public class ManagerRegistry extends Object
A registry for managing and injecting manager instances.
  • Constructor Details

    • ManagerRegistry

      public ManagerRegistry(JavaPlugin plugin)
      Creates a new ManagerRegistry for the given plugin. Doesn't require the Manager annotation on managed classes.
      Parameters:
      plugin - The main plugin instance.
    • ManagerRegistry

      public ManagerRegistry(JavaPlugin plugin, boolean requireManagerAnnotation, String packagePrefix)
      Creates a new ManagerRegistry for the given plugin.
      Parameters:
      plugin - The main plugin instance.
      requireManagerAnnotation - Whether to require the Manager annotation on managed classes.
  • Method Details

    • initializeEagerManagers

      public void initializeEagerManagers()
      Initializes and registers all eagerly loaded singleton managers found in the specified package.
    • registerInstance

      public void registerInstance(Object instance)
      Registers an existing instance in the registry.
      Parameters:
      instance - The instance to register.
    • registerInstance

      public void registerInstance(Class<?> cls, Object instance)
      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

      public <T> T getOrCreate(Class<T> cls)
      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

      public void injectManagers(Object target)
      Injects manager instances into the fields of the target object.
      Parameters:
      target - The target object to inject managers into.