Note that there are some explanatory texts on larger screens.

plurals
  1. POGuice And Scala - Injection on Generics Dependencies
    text
    copied!<p>I'm trying to create a binding of a generic trait using Guice</p> <p>See how the <code>trait</code> is defined</p> <pre><code>trait Repository[T] </code></pre> <p>See the <code>trait</code> implementation</p> <pre><code>class DomainRepository extends Repository[Domain] </code></pre> <p>My configure method in <code>DomainPersistenceModule</code> is:</p> <pre><code>def configure() { bind(classOf[Repository[Domain]]) .annotatedWith(classOf[DomainDependency]) .to(classOf[DomainRepository]) .in(Scopes.SINGLETON) } </code></pre> <p>The variable whose dependence will be injected is:</p> <pre><code> @Inject @DomainDependency var repository:Repository[Domain] = _ </code></pre> <p>The injection occurs here:</p> <pre><code>val injector:Injector = Guice.createInjector(new PersistenceModule()) val persistenceService:PersistenceService = injector.getInstance(classOf[DomainPersistenceService]) </code></pre> <p>The error is:</p> <pre><code>Caused by: com.google.inject.ConfigurationException: Guice configuration errors: 1) No implementation for repository.Repository&lt;domain.Domain&gt; annotated with @module.annotation.DomainDependency() was bound. while locating repository.Repository&lt;domain.Domain&gt; annotated with @module.annotation.DomainDependency() for field at service.persistence.DomainPersistenceService.repository(DomainPersistenceService.scala:19) while locating service.persistence.DomainPersistenceService </code></pre> <p>Am I missing something? Thanks in advance</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload