I would appreciate if I could get some help with the following. I am trying 
to do dependency injection for traits that have bounded parameter type. I 
am consistently having 

No implementation for dao.ImageDAO<models.ProductImageSet> was bound. while 
locating dao.ImageDAO<models.ProductImageSet>


trait ImageDAO[T <: ImageSet] {

  def find(id: String): ImageDisplay[T]

  def find(req: ImageSearch): ImageResponse[T]
}

class ProductImageDAO @Inject() (environment: Environment) extends 
ImageDAO[ProductImageSet] {
...
}

class ProfileImageDAO @Inject() (environment: Environment) extends 
ImageDAO[ProfileImageSet] {
...
}

case class ProductImageSet(swatchImage: BaseImage, smallImage: BaseImage, 
mediumImage: BaseImage, largeImage: BaseImage) extends ImageSet

case class ProfileImageSet(smallImage: BaseImage, mediumImage: BaseImage) 
extends ImageSet


And now, the service trait and its implementation

trait ImageService[A <: ImageSet] {
  def retrieve(id: String): ImageDisplay[A]

  def retrieve(req: ImageSearch): ImageResponse[A]
}

class ImageServiceImpl[T <: ImageSet] @Inject() (imageDAO: ImageDAO[T]) extends 
ImageService[T] {

  def retrieve(id: String): ImageDisplay[T] = imageDAO.find(id)

  def retrieve(req: ImageSearch): ImageResponse[T] = ???
}


Here is my class Module.scala where I want the dependency injection to 
happen.

class MyModule extends AbstractModule {
  protected override def configure() {
    bind(new 
TypeLiteral[ImageDAO[ProductImageSet]](){}).to(classOf[ProductImageDAO]).asEagerSingleton()
    bind(new 
TypeLiteral[ImageService[ProfileImageSet]](){}).to(classOf[ImageServiceImpl[ProfileImageSet]]).asEagerSingleton()
    bind(new 
TypeLiteral[ImageService[ProductImageSet]](){}).to(classOf[ImageServiceImpl[ProductImageSet]]).asEagerSingleton()
   }

}

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-guice+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/36907e94-1941-4069-8b25-3e511ebd8fbb%40googlegroups.com.

Reply via email to