title: Dependency injection with @Inject and Interface in Quarkus
body: <p>I'm trying to resolve dependency injection with Repository Pattern using Quarkus 1.6.1.Final and OpenJDK 11.
  I want to achieve Inject with Interface and give them some argument(like <code>@Named</code> or <code>@Qualifier</code> ) for specify the concrete class, but currently I've got <code>UnsatisfiedResolutionException</code> and not sure how to fix it.</p>
  <p>Here is the my portion of code.</p>
  <p>UseCase class:</p>
  <pre><code>@ApplicationScoped
  public class ProductStockCheckUseCase {
      @Inject
      @Named(&quot;dummy&quot;)
      ProductStockRepository repo;
  
      public int checkProductStock() {
          ProductStock stock = repo.findBy(&quot;&quot;);
          return stock.getCount();
      }
  }
  </code></pre>
  <p>Repository Interface:</p>
  <pre><code>public interface ProductStockRepository {
      public ProductStock findBy(String productId);
  }
  </code></pre>
  <p>Repository Implementation:</p>
  <pre><code>@Named(&quot;dummy&quot;)
  public class ProductStockDummyRepository implements ProductStockRepository {
  
      public ProductStock findBy(final String productId) {
          final ProductStock productStock = new ProductStock();
          return productStock;
      }
  }
  </code></pre>
  <p>And here is a portion of my build.gradle's dependencies:</p>
  <pre><code>dependencies {
      implementation 'io.quarkus:quarkus-resteasy'
      implementation 'io.quarkus:quarkus-arc'
      implementation enforcedPlatform(&quot;${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}&quot;)
  
      testImplementation 'io.quarkus:quarkus-junit5'
      testImplementation 'io.rest-assured:rest-assured'
  }
  </code></pre>
  <p>When I run this (e.g. <code>./gradlew assemble</code> or <code>./gradlew quarkusDev</code> ), I've got the following errors:</p>
  <pre><code>Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type ProductStockRepository and qualifiers [@Named(value = &quot;dummy&quot;)]
          - java member: ProductStockCheckUseCase#repo
          - declared on CLASS bean [types=[ProductStockCheckUseCase, java.lang.Object], qualifiers=[@Default, @Any], target=ProductStockCheckUseCase]
  </code></pre>
  <p>Do you have any ideas how to fix this? or is it wrong idea to implement this kind of interface injection and specify the concrete class with argument/annotation?</p>
  <p>I've read and tried the following articles:</p>
  <p>Some official docs:</p>
  <ul>
  <li>Quarkus - Contexts and Dependency Injection <a href="https://quarkus.io/guides/cdi-reference" rel="noreferrer">https://quarkus.io/guides/cdi-reference</a></li>
  <li>JSR 365: Contexts and Dependency Injection for Java 2.0 <a href="https://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#default_bean_discovery" rel="noreferrer">https://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#default_bean_discovery</a></li>
  <li>Interfaces on Demand with CDI and EJB 3.1 <a href="https://www.oracle.com/technical-resources/articles/java/intondemand.html" rel="noreferrer">https://www.oracle.com/technical-resources/articles/java/intondemand.html</a></li>
  <li>23.7 Injecting Beans - Java Platform, Enterprise Edition: The Java EE Tutorial (Release 7) <a href="https://docs.oracle.com/javaee/7/tutorial/cdi-basic007.htm" rel="noreferrer">https://docs.oracle.com/javaee/7/tutorial/cdi-basic007.htm</a></li>
  </ul>
  <p>The other blogs and SOs:</p>
  <ul>
  <li>java - how inject implementation of JpaRepository - Stack Overflow <a href="https://stackoverflow.com/questions/60601330/how-inject-implementation-of-jparepository">how inject implementation of JpaRepository</a></li>
  <li>java - How to inject two instances of two different classes which implement the same interface? - Stack Overflow <a href="https://stackoverflow.com/questions/55618095/how-to-inject-two-instances-of-two-different-classes-which-implement-the-same-in">How to inject two instances of two different classes which implement the same interface?</a></li>
  <li>Java EE Context and Dependency Injection @Qualifier <a href="https://memorynotfound.com/context-dependency-injection-qualifier/" rel="noreferrer">https://memorynotfound.com/context-dependency-injection-qualifier/</a></li>
  </ul>