File tree 3 files changed +20
-0
lines changed
main/scala/net/codingwell/scalaguice
test/scala/net/codingwell/scalaguice
3 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ package net.codingwell.scalaguice
18
18
import com .google .inject ._
19
19
import binder ._
20
20
import java .lang .annotation .Annotation
21
+ import javax .inject .Provider
21
22
22
23
/**
23
24
* Allows binding via type parameters. Mix into <code>AbstractModule</code>
Original file line number Diff line number Diff line change @@ -57,3 +57,13 @@ class GenStringProvider extends Provider[Gen[String]] {
57
57
class CProvider extends Provider [C ] {
58
58
def get = new C
59
59
}
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
+ }
Original file line number Diff line number Diff line change @@ -88,6 +88,15 @@ class ScalaModuleSpec extends WordSpec with ShouldMatchers {
88
88
Guice .createInjector(module).getInstance(Key .get(classOf [A ],classOf [Named ]))
89
89
}
90
90
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
+
91
100
" give a useful error when bound on itself" in {
92
101
val module = new AbstractModule with ScalaModule {
93
102
def configure () = {
You can’t perform that action at this time.
0 commit comments