Uploaded image for project: 'Tapestry 5'
  1. Tapestry 5
  2. TAP5-2637

Provide API to query multiple/all service instances from ObjectLocator by service interface/markers

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: tapestry-ioc
    • Labels:
      None

      Description

      Tapestry IoC's `ObjectLocator` can only return a service if there's exactly one implementation matching criteria:

       

      <T> T getService(Class<T> serviceInterface)
      <T> T getService(Class<T> serviceInterface, Class<? extends Annotation>... markerTypes);
      

      It's sometimes necessary to get all registered services, i.e. when integrating with 3rd party libraries that support "bring your own service discovery", they expect this functionality from service discovery.

      At present `RegistryImpl` has everything we need to implement this feature, see `#findServiceIdsForInterface` and `#findServiceDefsMatchingMarkerAndType`.

       

      As future work we could also support list-type injections, i.e.

      @Inject List<ServiceA> multipleInjections;

      Marker annotations would fit nicely here, e.g. `@Inject @Blue List<ServiceA> multipleInjections;`

      In theory it may break injections for services that implement the `List` interface itself, unsure if there are any real use-cases for it. But as all service definitions are known upfront on registry initialisation we may implement a safety check and fail with error if there's any. We may also provide a symbol to disable List-injections, and only run the mentioned check/failure if the symbol is enabled.

       

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              dmitrygusev Dmitry Gusev
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: