Class Services<T>

java.lang.Object
com.gluonhq.attach.util.Services<T>

public class Services<T> extends Object
  • Method Details

    • registerServiceFactory

      public static <T> void registerServiceFactory(ServiceFactory<T> factory)
      Required call to register a ServiceFactory for a given service of type T. ServiceFactory instance is cached. In case a service is called without its ServiceFactory being registered first, a Runtime Exception will be thrown
      Type Parameters:
      T - The type of service
      Parameters:
      factory - The ServiceFactory instance
    • get

      public static <T> Optional<T> get(Class<T> service)
      Returns an optional with a service, if previously a ServiceFactory was registered. Otherwise, it will try to find a service factory in the same package as the service, and otherwise a Runtime Exception will be thrown. Both serviceFactory and service instances are cached, so only one service is created for the given factory
      Type Parameters:
      T - the type of service
      Parameters:
      service - the class of service
      Returns:
      An optional with the service