hk2
  1. hk2
  2. HK2-30 Modular binding & injection API
  3. HK2-47

Ability to bind single class/factory/instance to multiple contracts.

    Details

    • Type: Sub-task Sub-task
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.*
    • Fix Version/s: 2.1.*
    • Component/s: None
    • Labels:
      None

      Description

      Currently the following code

        binderFactory.bind(ContractA.class).to(Service.class);
        binderFactory.bind(ContractB.class).to(Service.class);
      

      or

        binderFactory.bind(ContractA.class).toFactory(ServiceFactory.class).in(SomeScope.class);
        binderFactory.bind(ContractB.class).toFactory(ServiceFactory.class).in(SomeScope.class);
      

      results in 2 separate instances of Service/ServiceFactory class being constructed to resolve the injection of ContractA or ContractB respectively.

      While sometimes this may be desired, more often the scenario requires that both ContractA as well as ContractB are resolved using just the same single instance of Service/ServiceFactory class in a given scope.

      Resolving the problem with the current API is currently not intuitive and error prone.

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            jwells
            Reporter:
            Marek Potociar
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: