Class IoC


  • public class IoC
    extends java.lang.Object
    Author:
    Collin Alpert An
    Inversion of Control
    container. It is responsible for registering and resolving services.
    • Constructor Summary

      Constructors 
      Constructor Description
      IoC()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <S extends BaseService>
      boolean
      isRegistered​(java.lang.Class<S> clazz)
      Checks if a service has already been registered.
      static <E extends BaseEntity,​S extends BaseService<E>>
      void
      registerService​(java.lang.Class<E> clazz, S service)
      Registers an instance of a service class.
      static <E> E resolve​(java.lang.Class<E> clazz)
      Creates an instance of any class with an empty constructor.
      static <S extends BaseService>
      S
      resolveService​(java.lang.Class<S> clazz)
      Resolves a service class.
      static <E extends BaseEntity,​S extends BaseService<E>>
      S
      resolveServiceByEntity​(java.lang.Class<E> clazz)
      Resolves a service class by the entity it was registered with.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • IoC

        public IoC()
    • Method Detail

      • resolve

        public static <E> E resolve​(java.lang.Class<E> clazz)
        Creates an instance of any class with an empty constructor.
        Type Parameters:
        E - The type of the entity.
        Parameters:
        clazz - The class to be constructed.
        Returns:
        An instance of this class.
        Throws:
        java.lang.IllegalArgumentException - if the class cannot be constructed for any reason. This can occur if there is no public parameterless constructor available.
      • resolveService

        public static <S extends BaseService> S resolveService​(java.lang.Class<S> clazz)
        Resolves a service class. This is to preserve the singleton pattern. Only one instance of a service is needed in the lifecycle of an application.
        Type Parameters:
        S - The type of the service class.
        Parameters:
        clazz - The service class to retrieve.
        Returns:
        The previously registered instance of a service class.
      • resolveServiceByEntity

        public static <E extends BaseEntity,​S extends BaseService<E>> S resolveServiceByEntity​(java.lang.Class<E> clazz)
        Resolves a service class by the entity it was registered with.
        Type Parameters:
        E - The type of the entity.
        S - The type of the service.
        Parameters:
        clazz - The entity class corresponding to a service class.
        Returns:
        An instance of a previously registered service class.
      • registerService

        public static <E extends BaseEntity,​S extends BaseService<E>> void registerService​(java.lang.Class<E> clazz,
                                                                                                 S service)
        Registers an instance of a service class.
        Type Parameters:
        E - The type of the entity.
        S - The type of the service class.
        Parameters:
        clazz - An entity class.
        service - The service class this entity corresponds to.
      • isRegistered

        public <S extends BaseService> boolean isRegistered​(java.lang.Class<S> clazz)
        Checks if a service has already been registered.
        Type Parameters:
        S - The type of the service.
        Parameters:
        clazz - The class os the service.
        Returns:
        True if an instance of the service is registered, false if not.