Skip to content

Commit 3dbe96f

Browse files
committed
Merge pull request codingwell#18 from michalkowol/develop
Use javax.inject.Provider
2 parents f2eb732 + a81fbf6 commit 3dbe96f

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/main/scala/net/codingwell/scalaguice/ScalaModule.scala

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package net.codingwell.scalaguice
1818
import com.google.inject._
1919
import binder._
2020
import java.lang.annotation.Annotation
21+
import javax.inject.Provider
2122

2223
/**
2324
* Allows binding via type parameters. Mix into <code>AbstractModule</code>

src/test/scala/net/codingwell/scalaguice/ClassesForTesting.scala

+10
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,13 @@ class GenStringProvider extends Provider[Gen[String]] {
5757
class CProvider extends Provider[C] {
5858
def get = new C
5959
}
60+
61+
trait Foo {
62+
def foo(): String
63+
}
64+
65+
class FooProviderWithJavax extends javax.inject.Provider[Foo] {
66+
def get(): Foo = new Foo {
67+
def foo() = "foo"
68+
}
69+
}

src/test/scala/net/codingwell/scalaguice/ScalaModuleSpec.scala

+9
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ class ScalaModuleSpec extends WordSpec with ShouldMatchers {
8888
Guice.createInjector(module).getInstance(Key.get(classOf[A],classOf[Named]))
8989
}
9090

91+
"allow use provider form javax.inject.Provider" in {
92+
val module = new AbstractModule with ScalaModule {
93+
def configure() {
94+
bind[Foo].toProvider[FooProviderWithJavax]
95+
}
96+
}
97+
Guice.createInjector(module).getInstance(classOf[Foo])
98+
}
99+
91100
"give a useful error when bound on itself" in {
92101
val module = new AbstractModule with ScalaModule {
93102
def configure() = {

0 commit comments

Comments
 (0)