ServiceRegistry

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(Class<T> type)     (2)
  Stream<_SingletonBeanProvider> streamRegisteredBeansOfType(Class<?> requiredType)     (3)
  Stream<_SingletonBeanProvider> streamRegisteredBeans()     (4)
  Optional<_SingletonBeanProvider> lookupRegisteredBeanById(LogicalType id)     (5)
  _SingletonBeanProvider lookupRegisteredBeanByIdElseFail(LogicalType id)     (6)
  Optional<?> lookupBeanById(String id)
  Optional<T> lookupService(Class<T> serviceClass)     (7)
  Optional<T> lookupService(Class<T> serviceClass, Comparator<Object> comparator)     (8)
  T lookupServiceElseFail(Class<T> serviceClass)     (9)
  void clearRegisteredBeans()     (10)
}
1 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(LogicalType)

Returns a registered bean of given name .

6 lookupRegisteredBeanByIdElseFail(LogicalType)

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(LogicalType)

Returns a registered bean of given name .

lookupRegisteredBeanByIdElseFail(LogicalType)

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.c.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);