java.lang.Object
com.gluonhq.attach.util.Services<T>
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Optional<T>
Returns an optional with a service, if previously a ServiceFactory was registered.static <T> void
registerServiceFactory
(ServiceFactory<T> factory) Required call to register a ServiceFactory for a given service of type T.
-
Method Details
-
registerServiceFactory
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
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
-