codingwell / scala-guice

Scala extensions for Google Guice
Apache License 2.0
341 stars 44 forks source link

Use javax.inject.Provider #17

Closed michalkowol closed 10 years ago

michalkowol commented 10 years ago

If you use import: import javax.inject.Provider you cannot use bind[A].toProvider[AProvider], but tou must use bind[A].toProvider(classOf[AProvider])

Example:

trait A {
  def foo(): String
}

class AProvider extends javax.inject.Provider[A] {
  def get(): A = new A {
    def foo(): String = "foo"
  }
}

class AModule extends AbstractModule with ScalaModule {
  def configure() {
    bind[A].toProvider(classOf[AProvider]) // ok
   //bind[A].toProvider[AProvider] // fails!
  }
}

Solution: argument in net.codingwell.scalaguice.ScalaLinkedBindingBuilder.toProvider should be javax.inject.Provider insted of com.google.inject.Provider (note that Provider from guice only extends Provider from javax.inject).

tsuckow commented 10 years ago

I'll have to look into that.

Pull requests are always welcome as well. ; )

tsuckow commented 10 years ago

I assume you are using Google Guice/scala-guice 4-beta ?

michalkowol commented 10 years ago

Yes, I am using scala-guice 4-beta. Issue fixed in #18.

tsuckow commented 10 years ago

I'm not going to bother backporting this to 3.x unless someone asks for it in a new ticket.