Interface ServiceRegistry


@Contract public interface ServiceRegistry
Entry point to services in Helidon.

The service registry has knowledge about all the services within your application.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final TypeName
    Type name of this interface.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> List<T>
    all(TypeName contract)
    Get all service instances matching the contract with the expectation that there may not be a match available.
    default <T> List<T>
    all(Class<T> contract)
    Get all service instances matching the contract with the expectation that there may not be a match available.
    Get all services for a specific contract.
    default List<ServiceInfo>
    allServices(Class<?> contract)
    Get all services for a specific contract.
    <T> Optional<T>
    first(TypeName contract)
    Get the first service instance matching the contract with the expectation that there may not be a match available.
    default <T> Optional<T>
    first(Class<T> contract)
    Get the first service instance matching the contract with the expectation that there may not be a match available.
    <T> T
    get(TypeName contract)
    Get the first service instance matching the contract with the expectation that there is a match available.
    <T> Optional<T>
    get(ServiceInfo serviceInfo)
    Provide a value for a specific service info instance.
    default <T> T
    get(Class<T> contract)
    Get the first service instance matching the contract with the expectation that there is a match available.
    <T> Supplier<T>
    supply(TypeName contract)
    Get the first service supplier matching the contract with the expectation that there is a match available.
    default <T> Supplier<T>
    supply(Class<T> contract)
    Get the first service supplier matching the contract with the expectation that there is a match available.
    <T> Supplier<List<T>>
    supplyAll(TypeName contract)
    Lookup a supplier of a list of instances of the requested contract, with the expectation that there may not be a match available.
    default <T> Supplier<List<T>>
    supplyAll(Class<T> contract)
    Lookup a supplier of a list of instances of the requested contract, with the expectation that there may not be a match available.
    Get the first service supplier matching the contract with the expectation that there may not be a match available.
    default <T> Supplier<Optional<T>>
    supplyFirst(Class<T> contract)
    Get the first service supplier matching the contract with the expectation that there may not be a match available.
  • Field Details

    • TYPE

      static final TypeName TYPE
      Type name of this interface.
  • Method Details

    • get

      default <T> T get(Class<T> contract)
      Get the first service instance matching the contract with the expectation that there is a match available.
      Type Parameters:
      T - type of the contract
      Parameters:
      contract - contract to look-up
      Returns:
      the best service instance matching the contract
      Throws:
      ServiceRegistryException - if there is no service that could satisfy the lookup, or the resolution to instance failed
    • get

      <T> T get(TypeName contract)
      Get the first service instance matching the contract with the expectation that there is a match available.
      Type Parameters:
      T - type of the contract (we will "blindly" cast the result to the expected type, make sure you use the right one)
      Parameters:
      contract - contract to look-up
      Returns:
      the best service instance matching the contract
      Throws:
      ServiceRegistryException - if there is no service that could satisfy the lookup, or the resolution to instance failed
    • first

      default <T> Optional<T> first(Class<T> contract)
      Get the first service instance matching the contract with the expectation that there may not be a match available.
      Type Parameters:
      T - type of the contract
      Parameters:
      contract - contract to look-up
      Returns:
      the best service instance matching the contract, or an empty Optional if none match
      Throws:
      ServiceRegistryException - if there is no service that could satisfy the lookup, or the resolution to instance failed
    • first

      <T> Optional<T> first(TypeName contract)
      Get the first service instance matching the contract with the expectation that there may not be a match available.
      Type Parameters:
      T - type of the contract
      Parameters:
      contract - contract to look-up
      Returns:
      the best service instance matching the contract, or an empty Optional if none match
      Throws:
      ServiceRegistryException - if there is no service that could satisfy the lookup, or the resolution to instance failed
    • all

      default <T> List<T> all(Class<T> contract)
      Get all service instances matching the contract with the expectation that there may not be a match available.
      Type Parameters:
      T - type of the contract
      Parameters:
      contract - contract to look-up
      Returns:
      list of services matching the criteria, may be empty if none matched, or no instances were provided
    • all

      <T> List<T> all(TypeName contract)
      Get all service instances matching the contract with the expectation that there may not be a match available.
      Type Parameters:
      T - type of the contract
      Parameters:
      contract - contract to look-up
      Returns:
      list of services matching the criteria, may be empty if none matched, or no instances were provided
    • supply

      default <T> Supplier<T> supply(Class<T> contract)
      Get the first service supplier matching the contract with the expectation that there is a match available. The provided Supplier.get() may throw an ServiceRegistryException in case the matching service cannot provide a value (either because of scope mismatch, or because an instance was not provided by the service provider.
      Type Parameters:
      T - type of the contract
      Parameters:
      contract - contract to find
      Returns:
      the best service supplier matching the lookup
      Throws:
      ServiceRegistryException - if there is no service that could satisfy the lookup
    • supply

      <T> Supplier<T> supply(TypeName contract)
      Get the first service supplier matching the contract with the expectation that there is a match available. The provided Supplier.get() may throw an ServiceRegistryException in case the matching service cannot provide a value (either because of scope mismatch, or because an instance was not provided by the service provider.
      Type Parameters:
      T - type of the contract
      Parameters:
      contract - contract to find
      Returns:
      the best service supplier matching the lookup
      Throws:
      ServiceRegistryException - if there is no service that could satisfy the lookup
    • supplyFirst

      default <T> Supplier<Optional<T>> supplyFirst(Class<T> contract)
      Get the first service supplier matching the contract with the expectation that there may not be a match available.
      Type Parameters:
      T - type of the contract
      Parameters:
      contract - contract we look for
      Returns:
      supplier of an optional instance
    • supplyFirst

      <T> Supplier<Optional<T>> supplyFirst(TypeName contract)
      Get the first service supplier matching the contract with the expectation that there may not be a match available.
      Type Parameters:
      T - type of the contract
      Parameters:
      contract - contract we look for
      Returns:
      supplier of an optional instance
    • supplyAll

      default <T> Supplier<List<T>> supplyAll(Class<T> contract)
      Lookup a supplier of a list of instances of the requested contract, with the expectation that there may not be a match available.
      Type Parameters:
      T - type of the contract
      Parameters:
      contract - contract we look for
      Returns:
      a supplier of list of instances
    • supplyAll

      <T> Supplier<List<T>> supplyAll(TypeName contract)
      Lookup a supplier of a list of instances of the requested contract, with the expectation that there may not be a match available.
      Type Parameters:
      T - type of the contract
      Parameters:
      contract - contract we look for
      Returns:
      a supplier of list of instances
    • get

      <T> Optional<T> get(ServiceInfo serviceInfo)
      Provide a value for a specific service info instance. This method uses instance equality for service info, so be careful to use the singleton instance from the service descriptor, or instances provided by allServices(Class).
      Type Parameters:
      T - type of the expected instance, we just cast to it, so this may cause runtime issues if assigned to invalid type
      Parameters:
      serviceInfo - service info instance
      Returns:
      value of the service described by the service info provided (always a single value), as there is support for providers that are Supplier of an instance, and that may return Optional, we may not get a value, hence we return Optional as well
    • allServices

      default List<ServiceInfo> allServices(Class<?> contract)
      Get all services for a specific contract. The list may be empty if there are no services available. To get an instance, use get(ServiceInfo).
      Parameters:
      contract - contract we look for
      Returns:
      list of service metadata of services that satisfy the provided contract
    • allServices

      List<ServiceInfo> allServices(TypeName contract)
      Get all services for a specific contract. The list may be empty if there are no services available. To get an instance, use get(ServiceInfo).
      Parameters:
      contract - contract we look for
      Returns:
      list of service metadata of services that satisfy the provided contract