hk2
  1. hk2
  2. HK2-171

Ability to bind Contract to instance

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Works as designed
    • Affects Version/s: 2.1.*
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      AbstractBinder.bind(T service) binds an instance to its own type, but there is no obvious way to do the following:

      Implementation implementation = ...;
      bind(Interface.class).to(implementation);
      

        Activity

        Hide
        cowwoc added a comment -

        This also affects BuilderHelper and Description classes.

        Show
        cowwoc added a comment - This also affects BuilderHelper and Description classes.
        Hide
        cowwoc added a comment -

        It looks like this use-case is already covered by: AbstractBinder.bind(BuilderHelper.createConstantDescriptor(implementation, null, Interface.class).

        Is it possible to add this functionality to AbstractBinder so we don't have to look for binding options in two separate classes?

        Show
        cowwoc added a comment - It looks like this use-case is already covered by: AbstractBinder.bind(BuilderHelper.createConstantDescriptor(implementation, null, Interface.class) . Is it possible to add this functionality to AbstractBinder so we don't have to look for binding options in two separate classes?
        Hide
        jwells added a comment -

        I don't even think you need to use BuilderHelper. Why wouldn't this just work:

        bind(implementation).to(Interface.class)

        ?

        In fact I think this does work.

        Show
        jwells added a comment - I don't even think you need to use BuilderHelper. Why wouldn't this just work: bind(implementation).to(Interface.class) ? In fact I think this does work.
        Hide
        cowwoc added a comment -

        Apologies. You're right! I am coming from a Guice mindset where binding is from(interface).to(implementation), not the other way around, so I missed that function.

        Show
        cowwoc added a comment - Apologies. You're right! I am coming from a Guice mindset where binding is from(interface).to(implementation) , not the other way around, so I missed that function.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: