Hello, I am receiving the following stack trace when trying to run this 
small Scala/Guice example, I am suspecting that it has to do with 
Seq<Tuple2<String, String>> and somehow it is not mapping right.  Hope 
someone has a good solution.  

1) No implementation for 
scala.collection.Seq<scala.Tuple2<java.lang.String, java.lang.String>> 
annotated with @com.google.inject.name.Named(value=countries) was bound.
  while locating scala.collection.Seq<scala.Tuple2<java.lang.String, 
java.lang.String>> annotated with 
@com.google.inject.name.Named(value=countries)
    for the 2nd parameter of MyComponent.<init>(MyComponent.scala:3)
  at MyModule.configure(MyModule.scala:18)

2) No implementation for 
scala.collection.Seq<scala.Tuple2<java.lang.String, java.lang.String>> 
annotated with @com.google.inject.name.Named(value=states) was bound.
  while locating scala.collection.Seq<scala.Tuple2<java.lang.String, 
java.lang.String>> annotated with 
@com.google.inject.name.Named(value=states)
    for the 1st parameter of MyComponent.<init>(MyComponent.scala:3)
  at MyModule.configure(MyModule.scala:18)

The following is the code, I have three classes, one is the Runner (the 
main class), My Component where items will be injected, and MyModule which 
is the Guice Module

*MyComponent.scala*

import javax.inject.{Inject, Named}

class MyComponent @Inject() (@Named("states") states: Seq[(String, String)],
                             @Named("countries") countries: Seq[(String, 
String)]) {
     def stateSize: Int = states.size
     def countrySize: Int = countries.size
}



*MyModule.scala*

import com.google.inject.name.Names.named
import com.google.inject.{AbstractModule, Provider, TypeLiteral}

import scala.collection.immutable.Seq

class MyModule extends AbstractModule {
  override def configure(): Unit = {
    bind(new TypeLiteral[Seq[(String, String)]]() {})
      .annotatedWith(named("states"))
      .toInstance(Seq("NY" -> "New York", "NJ" -> "New Jersey"))

    bind(new TypeLiteral[Seq[(String, String)]]() {})
      .annotatedWith(named("countries"))
      .toProvider(new Provider[Seq[(String, String)]] {
        override def get() = Seq(("US", "United States"), ("MX", "Mexico"))
      })

    bind(classOf[MyComponent])
  }
}


*Runner.scala*


import com.google.inject.{Guice, Injector}


object Runner extends App {
  val injector:Injector = Guice.createInjector(new MyModule())

  val instance: MyComponent = injector.getInstance(classOf[MyComponent])

  println(instance)
}


-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/6af19829-d632-42ff-b534-2a3df8ac63bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to