ServiceRegistry (interface)

Collects together methods for injecting or looking up domain services (either provided by the framework or application-specific) currently known to the runtime.

API

ServiceRegistry.java
interface ServiceRegistry {
  Can<T> select(Class<T> type, Annotation[] qualifiers)     (1)
  Can<T> select(final Class<T> type)     (2)
  Stream<_ManagedBeanAdapter> streamRegisteredBeansOfType(Class<?> requiredType)     (3)
  Stream<_ManagedBeanAdapter> streamRegisteredBeans()     (4)
  Optional<_ManagedBeanAdapter> lookupRegisteredBeanById(String id)     (5)
  _ManagedBeanAdapter lookupRegisteredBeanByIdElseFail(String id)     (6)
  Optional<?> lookupBeanById(final String id)
  Optional<T> lookupService(final Class<T> serviceClass)     (7)
  Optional<T> lookupService(Class<T> serviceClass, Comparator<Object> comparator)     (8)
  T lookupServiceElseFail(final Class<T> serviceClass)     (9)
  void clearRegisteredBeans()     (10)
}
1 [select__Class_Annotation][select(Class, Annotation[])]

Obtains a Can container containing any matching instances for the given required type and additional required qualifiers.

2 select(Class)

Obtains a Can container containing any matching instances for the given required type.

3 streamRegisteredBeansOfType(Class)

Streams all registered bean adapters implementing the requested type.

4 streamRegisteredBeans()

Returns all bean adapters that have been registered.

5 lookupRegisteredBeanById(String)

Returns a registered bean of given name .

6 lookupRegisteredBeanByIdElseFail(String)

Returns a registered bean of given name , or throws when no such bean.

7 lookupService(Class)

Returns a domain service implementing the requested type.

8 lookupService(Class, Comparator)

Returns a domain service implementing the requested type.

9 lookupServiceElseFail(Class)

Looks up a domain service of the requested type (same as #lookupService(Class) ) but throws a NoSuchElementException if there are no such instances.

10 clearRegisteredBeans()

Invalidates any cached service adapters that might hold a reference to the current SpecificationLoader . Particularly useful when discarding a meta-model instance, that is, purging the ObjectSpecification cache.

Members

select(Class, Annotation[])

Obtains a Can container containing any matching instances for the given required type and additional required qualifiers.

select(Class)

Obtains a Can container containing any matching instances for the given required type.

streamRegisteredBeansOfType(Class)

Streams all registered bean adapters implementing the requested type.

streamRegisteredBeans()

Returns all bean adapters that have been registered.

lookupRegisteredBeanById(String)

Returns a registered bean of given name .

lookupRegisteredBeanByIdElseFail(String)

Returns a registered bean of given name , or throws when no such bean.

lookupService(Class)

Returns a domain service implementing the requested type.

If this lookup is ambiguous, the service annotated with highest priority is returned. see Priority

lookupService(Class, Comparator)

Returns a domain service implementing the requested type.

If this lookup is ambiguous, then the provided comparator is used.

lookupServiceElseFail(Class)

Looks up a domain service of the requested type (same as #lookupService(Class) ) but throws a NoSuchElementException if there are no such instances.

clearRegisteredBeans()

Invalidates any cached service adapters that might hold a reference to the current SpecificationLoader . Particularly useful when discarding a meta-model instance, that is, purging the ObjectSpecification cache.

Implementation

The core framework provides a default implementation of this service (o.a.i.core.metamodel.services.registry.ServiceRegistryDefault).

Usage

The primary use case is to lookup domain services programmatically (as an alternative to injection).

For example:

Service Lookup (Optional)
Optional<MyService> myServiceIfAny = serviceRegistry.lookupService(MyService.class);
Service Lookup (enforced non-null)
MyService myService = serviceRegistry.lookupServiceElseFail(MyService.class);