hk2
  1. hk2
  2. HK2-145

@ContractsProvided Interface Injection Does Not Work

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 2.2.0
    • Fix Version/s: 2.2.0
    • Component/s: None
    • Labels:
      None
    • Environment:

      Linux Mint 64bit
      JDK 7
      HK v2.2.0-b24

      Description

      Services annotated with @ContractsProvided are not injectable using the interface they provide. For example, HK2 throws UnsatisfiedDependencyException on the following.

      public interface MyService {
      
      }
      
      @ContractsProvided(MyService.class)
      @Service
      public class MyServiceImpl {
      
      }
      
      
      @Service
      public class SomeService {
      
        @Inject
        SomeService(MyService myService){
        }
      
      }
      
      

      Looking at the inhabitant file generated I see that service definition generated for the service looks something like this (notice "S-" at the end):

      [test.MyServiceImpl]S-
      contract={test.MyService}
      

      but if I directly annotate the MyService interface with @Contract the definition generated look something like this (notice that it ends in "S" and not "S-"):

      [test.MyServiceImpl]S
      contract={test.MyService}
      

        Activity

        Hide
        saden added a comment -

        Please disregard this issue. I forgot to annotate my constructor with @Inject.

        Sorry for the inconvenience.

        p.s. It would be nice if HK2 spat out a more descriptive exception if you forget to annotate your constructor with @Inject.

        Show
        saden added a comment - Please disregard this issue. I forgot to annotate my constructor with @Inject. Sorry for the inconvenience. p.s. It would be nice if HK2 spat out a more descriptive exception if you forget to annotate your constructor with @Inject.
        Hide
        jwells added a comment -

        Your MyServiceImpl class must implement MyService.

        The "-" after the S indicates that that implementation class should NOT be available in the list of contracts which is exactly what I would expect from your @ContractsProvided. When you use @ContractsProvided you will get as contracts only those things in the @ContractsProvided.

        Show
        jwells added a comment - Your MyServiceImpl class must implement MyService. The "-" after the S indicates that that implementation class should NOT be available in the list of contracts which is exactly what I would expect from your @ContractsProvided. When you use @ContractsProvided you will get as contracts only those things in the @ContractsProvided.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: