public class ServiceLocator extends Object
This class allows a separation of concern between Dragom and clients regarding the use of some service-like interfaces whose implementation should be selectable at runtime.
An example of such a service-like interface is JenkinsClient.
One motivation is to allow a testing client to inject test doubles for such service-like interfaces.
Although a dependency injection framework is not used to avoid imposing external dependencies on clients, such a framework can be used by clients if desired.
This class implements the following algorithm to provide service implementations to callers:
setServiceFactory(java.lang.Class<ServiceInterface>, org.azyva.dragom.util.ServiceLocator.ServiceFactory<ServiceInterface>). This
method could be called by a dependency injection framework such as
Spring. If a service factory is registered for a service interface, it is used
to create instances of the service interface;
| Modifier and Type | Class and Description |
|---|---|
static interface |
ServiceLocator.ServiceFactory<ServiceInterface>
Interface which must be implemented by registered service factories.
|
| Modifier and Type | Method and Description |
|---|---|
static <ServiceInterface> |
getService(Class<ServiceInterface> classServiceInterface) |
static <ServiceInterface> |
setServiceFactory(Class<ServiceInterface> classServiceInterface,
ServiceLocator.ServiceFactory<ServiceInterface> serviceFactory) |
public static <ServiceInterface> void setServiceFactory(Class<ServiceInterface> classServiceInterface, ServiceLocator.ServiceFactory<ServiceInterface> serviceFactory)
public static <ServiceInterface> ServiceInterface getService(Class<ServiceInterface> classServiceInterface)
Copyright © 2015–2016 AZYVA INC.. All rights reserved.