Module io.jooby
Package io.jooby

Interface ServiceRegistry

All Superinterfaces:
Registry

public interface ServiceRegistry extends Registry
Default registry which use a simply key/value mechanism for storing and retrieving services.
Since:
2.0.0
Author:
edgar
  • Method Summary

    Modifier and Type
    Method
    Description
    Set<Map.Entry<ServiceKey<?>,jakarta.inject.Provider<?>>>
    Registered service entries.
    default <T> T
    get(ServiceKey<T> key)
    Retrieve a service/resource by key.
    default <T> T
    get(Class<T> type)
    Retrieve a service/resource by key.
    <T> T
    Retrieve an existing service or null if not exists.
    default <T> T
    getOrNull(Class<T> type)
    Retrieve an existing service or null if not exists.
    Registered service keys.
    <T> T
    put(ServiceKey<T> key, jakarta.inject.Provider<T> service)
    Put a service in this registry.
    <T> T
    put(ServiceKey<T> key, T service)
    Put a service in this registry.
    default <T> T
    put(Class<T> type, jakarta.inject.Provider<T> service)
    Put a service in this registry.
    default <T> T
    put(Class<T> type, T service)
    Put a service in this registry.
    <T> T
    putIfAbsent(ServiceKey<T> key, jakarta.inject.Provider<T> service)
    Put/register a service in this registry if there isn't the same service already registered.
    <T> T
    putIfAbsent(ServiceKey<T> key, T service)
    Put/register a service in this registry if there isn't the same service already registered.
    default <T> T
    putIfAbsent(Class<T> type, jakarta.inject.Provider<T> service)
    Put/register a service in this registry if there isn't the same service already registered.
    default <T> T
    putIfAbsent(Class<T> type, T service)
    Put/register a service in this registry if there isn't the same service already registered.
    default <T> T
    Provides an instance of the given type.
    default <T> T
    require(Class<T> type)
    Provides an instance of the given type.
    default <T> T
    require(Class<T> type, String name)
    Provides an instance of the given type where name matches it.
  • Method Details

    • keySet

      @NonNull Set<ServiceKey<?>> keySet()
      Registered service keys.
      Returns:
      Service keys.
    • entrySet

      @NonNull Set<Map.Entry<ServiceKey<?>,jakarta.inject.Provider<?>>> entrySet()
      Registered service entries.
      Returns:
      Service entries.
    • get

      @NonNull default <T> T get(@NonNull ServiceKey<T> key)
      Retrieve a service/resource by key.
      Type Parameters:
      T - Service/resource type.
      Parameters:
      key - Service/resource key.
      Returns:
      Service.
      Throws:
      RegistryException - If there was a runtime failure while providing an instance.
    • get

      @NonNull default <T> T get(@NonNull Class<T> type)
      Retrieve a service/resource by key.
      Type Parameters:
      T - Service/resource type.
      Parameters:
      type - Service/resource key.
      Returns:
      Service.
      Throws:
      RegistryException - If there was a runtime failure while providing an instance.
    • getOrNull

      @Nullable <T> T getOrNull(@NonNull ServiceKey<T> key)
      Retrieve an existing service or null if not exists.
      Type Parameters:
      T - Service/resource type.
      Parameters:
      key - Service/resource key.
      Returns:
      Service or null.
    • getOrNull

      @Nullable default <T> T getOrNull(@NonNull Class<T> type)
      Retrieve an existing service or null if not exists.
      Type Parameters:
      T - Service/resource type.
      Parameters:
      type - Service/resource key.
      Returns:
      Service or null.
    • put

      @Nullable default <T> T put(@NonNull Class<T> type, jakarta.inject.Provider<T> service)
      Put a service in this registry. This method overrides any previous registered service.
      Type Parameters:
      T - Service type.
      Parameters:
      type - Service/resource key.
      service - Service instance.
      Returns:
      Previously registered service or null.
    • put

      @Nullable <T> T put(@NonNull ServiceKey<T> key, jakarta.inject.Provider<T> service)
      Put a service in this registry. This method overrides any previous registered service.
      Type Parameters:
      T - Service type.
      Parameters:
      key - Service/resource key.
      service - Service instance.
      Returns:
      Previously registered service or null.
    • put

      @Nullable default <T> T put(@NonNull Class<T> type, T service)
      Put a service in this registry. This method overrides any previous registered service.
      Type Parameters:
      T - Service type.
      Parameters:
      type - Service/resource key.
      service - Service instance.
      Returns:
      Previously registered service or null.
    • put

      @Nullable <T> T put(@NonNull ServiceKey<T> key, T service)
      Put a service in this registry. This method overrides any previous registered service.
      Type Parameters:
      T - Service type.
      Parameters:
      key - Service/resource key.
      service - Service instance.
      Returns:
      Previously registered service or null.
    • putIfAbsent

      @Nullable <T> T putIfAbsent(@NonNull ServiceKey<T> key, T service)
      Put/register a service in this registry if there isn't the same service already registered.
      Type Parameters:
      T - Service type.
      Parameters:
      key - Service/resource key.
      service - Service instance.
      Returns:
      Previously registered service or null.
    • putIfAbsent

      @Nullable default <T> T putIfAbsent(@NonNull Class<T> type, T service)
      Put/register a service in this registry if there isn't the same service already registered.
      Type Parameters:
      T - Service type.
      Parameters:
      type - Service/resource key.
      service - Service instance.
      Returns:
      Previously registered service or null.
    • putIfAbsent

      @Nullable <T> T putIfAbsent(@NonNull ServiceKey<T> key, jakarta.inject.Provider<T> service)
      Put/register a service in this registry if there isn't the same service already registered.
      Type Parameters:
      T - Service type.
      Parameters:
      key - Service/resource key.
      service - Service instance.
      Returns:
      Previously registered service or null.
    • putIfAbsent

      @Nullable default <T> T putIfAbsent(@NonNull Class<T> type, jakarta.inject.Provider<T> service)
      Put/register a service in this registry if there isn't the same service already registered.
      Type Parameters:
      T - Service type.
      Parameters:
      type - Service/resource key.
      service - Service instance.
      Returns:
      Previously registered service or null.
    • require

      @NonNull default <T> T require(@NonNull Class<T> type)
      Description copied from interface: Registry
      Provides an instance of the given type.
      Specified by:
      require in interface Registry
      Type Parameters:
      T - Object type.
      Parameters:
      type - Object type.
      Returns:
      Instance of this type.
    • require

      @NonNull default <T> T require(@NonNull Class<T> type, @NonNull String name)
      Description copied from interface: Registry
      Provides an instance of the given type where name matches it.
      Specified by:
      require in interface Registry
      Type Parameters:
      T - Object type.
      Parameters:
      type - Object type.
      name - Object name.
      Returns:
      Instance of this type.
    • require

      @NonNull default <T> T require(@NonNull ServiceKey<T> key) throws RegistryException
      Description copied from interface: Registry
      Provides an instance of the given type.
      Specified by:
      require in interface Registry
      Type Parameters:
      T - Object type.
      Parameters:
      key - Object key.
      Returns:
      Instance of this type.
      Throws:
      RegistryException - If there was a runtime failure while providing an instance.