oracle.dbtools.plugin.api.di

## Interface InstanceLocator

- All Known Implementing Classes:
    Instances, Instances.Builder

      public interface InstanceLocator

  Allows the application to dynamically obtain instances of services with a specified combination of required type and qualifiers. In general it is preferred to use injection to resolve dependencies, but in certain situations, injection is not the most convenient way to obtain a service instance. For these cases `InstanceProvider` should be used. This facility should be used sparingly, frequent use indicates use of the Service Locator Pattern instead of the Dependency Injection Pattern.
  Author:
    cdivilly
  See Also:
    `InstanceProvider`, `TypeQualifier`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `INSTANCE_LOCATOR_ATTRIBUTE` Denotes the name of a `HttpServletRequest` attribute which if present on a request indicates an attribute whose value will be an instance of `InstanceLocator`
    `static String` | `INSTANTIATOR_TYPE_SUFFIX` Deprecated. The `Instantiator` concept has been deprecated

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `static InstanceLocator` | `empty()` Retrieve `InstanceLocator` implementation that never produces any matches
    `default <T> InstanceProvider<T>` | `select(Class<T> service)` Select all services matching the specified type.
    `default <T> InstanceProvider<T>` | `select(Class<T> service, Annotation... qualifiers)` Deprecated. Use `select(TypeQualifier)` instead
    `<T> InstanceProvider<T>` | `select(TypeQualifier<T> qualifier)` Select all services matching the specified `TypeQualifier`

- - ### Field Detail

    - #### INSTANCE_LOCATOR_ATTRIBUTE

          static final String INSTANCE_LOCATOR_ATTRIBUTE

      Denotes the name of a `HttpServletRequest` attribute which if present on a request indicates an attribute whose value will be an instance of `InstanceLocator`

           void doGet(final HttpServletRequest request,
               final HttpServletResponse response)
               throws ServletException, IOException {
             // Get request scoped InstanceLocator
             final InstanceLocator locator = (InstanceLocator) request
                 .getAttribute(InstanceLocator.INSTANCE_LOCATOR_ATTRIBUTE);
             if (locator != null) {
               final SomeService service = locator.select(SomeService.class);
               // use SomeService instance...
             }
           }

    - #### INSTANTIATOR_TYPE_SUFFIX

          @Deprecated
          static final String INSTANTIATOR_TYPE_SUFFIX

      Deprecated. The `Instantiator` concept has been deprecated
      Identifies the expected type name suffix for any type that can instantiate another type. See Accelerating Instantiation for more information on this topic.
      See Also:
        Constant Field Values

  - ### Method Detail

    - #### select

          default <T> InstanceProvider<T> select(Class<T> service)

      Select all services matching the specified type. Equivalent to `select(TypeQualifier.provides(service)`
      Type Parameters:
        `T` - The type of the service
      Parameters:
        `service` - The service to resolve
      Returns:
        `InstanceProvider` for the specified type. This value is never null.
      Since:
        19.3.0

    - #### select

          @Deprecated
          default <T> InstanceProvider<T> select(Class<T> service,
                                                             Annotation... qualifiers)

      Deprecated. Use `select(TypeQualifier)` instead
      Obtains a child Instance for the given required type and additional required qualifiers.
      Type Parameters:
        `T` - The type of the service to locate
      Parameters:
        `service` - The type (contract) of the service to retrieve
        `qualifiers` - Additional qualifiers that constrain which implementation to match
      Returns:
        `InstanceProvider` for the specified type and qualifiers. This value is never null.

    - #### select

          <T> InstanceProvider<T> select(TypeQualifier<T> qualifier)

      Select all services matching the specified `TypeQualifier`
      Type Parameters:
        `T` - The type of the service to locate
      Parameters:
        `qualifier` - The qualifier that constrains which implementation to match
      Returns:
        `InstanceProvider` for the specified type and qualifier. This value is never null.
      Since:
        19.3.0

    - #### empty

          static InstanceLocator empty()

      Retrieve `InstanceLocator` implementation that never produces any matches
      Returns:
        empty `InstanceLocator` instance
      Since:
        19.3.0

Copyright © 2010, 2022, Oracle and/or its affiliates.