File tree 5 files changed +54
-8
lines changed
core/src/main/kotlin/org/jlleitschuh/guice
5 files changed +54
-8
lines changed Original file line number Diff line number Diff line change @@ -3,12 +3,11 @@ package org.jlleitschuh.guice
3
3
import com.google.inject.Binder
4
4
import com.google.inject.Key
5
5
import com.google.inject.TypeLiteral
6
- import com.google.inject.binder.AnnotatedBindingBuilder
7
6
import org.jlleitschuh.guice.binder.AnnotatedBindingBuilderScope
8
7
import org.jlleitschuh.guice.binder.LinkedBindingBuilderScope
9
8
import kotlin.reflect.KClass
10
9
11
- class BinderScope
10
+ open class BinderScope
12
11
internal constructor (private val binder: Binder ) : Binder by binder {
13
12
14
13
/* *
@@ -25,7 +24,7 @@ internal constructor(private val binder: Binder) : Binder by binder {
25
24
/* *
26
25
* See the EDSL examples at [Binder].
27
26
*/
28
- override fun <T : Any > bind (key : Key <T >) =
27
+ override fun <T : Any > bind (key : Key <T >): LinkedBindingBuilderScope < T > =
29
28
LinkedBindingBuilderScope (binder.bind(key))
30
29
31
30
/* *
@@ -40,4 +39,8 @@ internal constructor(private val binder: Binder) : Binder by binder {
40
39
override fun <T : Any > bind (typeLiteral : TypeLiteral <T >): AnnotatedBindingBuilderScope <T > =
41
40
AnnotatedBindingBuilderScope (binder.bind(typeLiteral))
42
41
42
+
43
+ override fun newPrivateBinder (): PrivateBinderScope =
44
+ PrivateBinderScope (binder.newPrivateBinder())
45
+
43
46
}
Original file line number Diff line number Diff line change 1
1
package org.jlleitschuh.guice
2
2
3
3
import com.google.inject.Module
4
+ import com.google.inject.PrivateModule
4
5
5
6
/* *
6
7
* Creates a [Module] with the [BinderScope] being configured when [Module.configure]
7
8
* is called by Guice.
8
9
*/
9
10
fun module (configure : BinderScope .() -> Unit ) =
10
- Module { binder -> BinderScope (binder).configure() }
11
+ Module { binder -> BinderScope (binder).configure() }
12
+
13
+ /* *
14
+ * Creates a [PrivateModule] with the [PrivateBinderScope] being configured when [PrivateModule.configure]
15
+ * is called by Guice.
16
+ */
17
+ fun privateModule (configure : PrivateBinderScope .() -> Unit ) =
18
+ // The PrivateModule data type has some reflection checks to get the right type passed in. Easier to just use it.
19
+ object : PrivateModule () {
20
+ override fun configure () =
21
+ configure.invoke(PrivateBinderScope (binder()))
22
+
23
+ }
Original file line number Diff line number Diff line change
1
+ package org.jlleitschuh.guice
2
+
3
+ import com.google.inject.Key
4
+ import com.google.inject.PrivateBinder
5
+ import com.google.inject.TypeLiteral
6
+ import com.google.inject.binder.AnnotatedElementBuilder
7
+
8
+ class PrivateBinderScope
9
+ internal constructor (private val privateBinder: PrivateBinder ): BinderScope (privateBinder), PrivateBinder {
10
+
11
+ override fun skipSources (vararg classesToSkip : Class <* >): PrivateBinderScope {
12
+ return PrivateBinderScope (privateBinder.skipSources(* classesToSkip))
13
+ }
14
+
15
+ override fun withSource (source : Any ): PrivateBinder {
16
+ return PrivateBinderScope (privateBinder.withSource(source))
17
+ }
18
+
19
+ override fun expose (key : Key <* >) {
20
+ privateBinder.expose(key)
21
+ }
22
+
23
+ override fun expose (type : Class <* >): AnnotatedElementBuilder {
24
+ return privateBinder.expose(type)
25
+ }
26
+
27
+ override fun expose (type : TypeLiteral <* >): AnnotatedElementBuilder {
28
+ return privateBinder.expose(type)
29
+ }
30
+ }
Original file line number Diff line number Diff line change @@ -12,19 +12,19 @@ class AnnotatedBindingBuilderScope<T : Any>(
12
12
/* *
13
13
* See the EDSL examples at [com.google.inject.Binder].
14
14
*/
15
- fun annotatedWith (annotationType : KClass <out Annotation >): LinkedBindingBuilder <T > =
15
+ fun annotatedWith (annotationType : KClass <out Annotation >): LinkedBindingBuilderScope <T > =
16
16
annotatedWith(annotationType.java)
17
17
18
18
/* *
19
19
* See the EDSL examples at [com.google.inject.Binder].
20
20
*/
21
- override fun annotatedWith (annotationType : Class <out Annotation >): LinkedBindingBuilder <T > =
21
+ override fun annotatedWith (annotationType : Class <out Annotation >): LinkedBindingBuilderScope <T > =
22
22
LinkedBindingBuilderScope (annotatedBindingBuilder.annotatedWith(annotationType))
23
23
24
24
/* *
25
25
* See the EDSL examples at [com.google.inject.Binder].
26
26
*/
27
- override fun annotatedWith (annotation : Annotation ): LinkedBindingBuilder <T > =
27
+ override fun annotatedWith (annotation : Annotation ): LinkedBindingBuilderScope <T > =
28
28
LinkedBindingBuilderScope (annotatedBindingBuilder.annotatedWith(annotation))
29
29
30
30
}
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ open class LinkedBindingBuilderScope<T : Any>(
18
18
* See the EDSL examples at [com.google.inject.Binder].
19
19
*/
20
20
fun to (implementation : KClass <out T >): ScopedBindingBuilderScope =
21
- ScopedBindingBuilderScope ( to(implementation.java) )
21
+ to(implementation.java)
22
22
23
23
/* *
24
24
* See the EDSL examples at [com.google.inject.Binder].
You can’t perform that action at this time.
0 commit comments