ServiceLocator subtypes must be default instantiable (i.e. public static types with a no-arg constructor). Instances of ServiceLocators may be retained and reused by the RequestFactory service layer. @see Service#locator()
This service is the most fundamental service in an HK2 system. Every service locator starts with a ServiceLocator as a service, and hence ServiceLocators can be injected into every object managed by HK2.
A service locator can have a single parent. Services are looked up in the current service locator and in all the parents of the service locator. If multiple services exist that match the filter they will all be returned. Two services with the same priority are sorted first by service locator id and second by service id. This implies that services directly installed in a ServiceLocator have higher natural priority than those in the parents of the ServiceLocator. Services can also be marked as having visibility LOCAL, in which case they will only be available to the ServiceLocator performing the lookup, and will not leak out to children of that ServiceLocator.
RepositorySystem repoSystem = serviceLocator.getService( RepositorySystem.class );to acquire the repository system. Components that implement {@link Service} will be given an opportunity to acquirefurther components from the locator, thereby allowing to create the complete object graph of the repository system. @author Benjamin Bentmann
The Service Locator provides the following operations.
It's still an anti-pattern, but at least this way callers don't use Component.getInstance() directly, and ServiceLocator can be subclassed to return mock objects for testing. @author Sean Flanigan sflaniga@redhat.com
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|