Skip to content

Commit f2c883b

Browse files
committed
Make use of FlavorBinder#scope when injecting into fields
1 parent a229883 commit f2c883b

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/main/kotlin/gg/scala/flavor/Flavor.kt

+18-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class Flavor(
9696
}
9797
}
9898

99-
fun tracked(lambda: () -> Unit): Long
99+
private fun tracked(lambda: () -> Unit): Long
100100
{
101101
val start = System.currentTimeMillis()
102102
lambda.invoke()
@@ -106,8 +106,15 @@ class Flavor(
106106

107107
private fun scanAndInject(clazz: KClass<*>, instance: Any? = null)
108108
{
109-
val singleton = instance ?: InjectScope.SINGLETON
110-
.instanceCreator.invoke(clazz)
109+
val singletonRaw = try
110+
{
111+
InjectScope.SINGLETON
112+
.instanceCreator.invoke(clazz)
113+
} catch (exception: Exception)
114+
{
115+
null
116+
}
117+
val singleton = instance ?: singletonRaw!!
111118

112119
for (field in clazz.java.fields)
113120
{
@@ -138,6 +145,14 @@ class Flavor(
138145
val accessability = field.isAccessible
139146

140147
binder?.let {
148+
if (binder.scope == InjectScope.SINGLETON)
149+
{
150+
if (singletonRaw == null)
151+
{
152+
return@let
153+
}
154+
}
155+
141156
field.isAccessible = false
142157
field.set(singleton, it.instance)
143158
field.isAccessible = accessability

0 commit comments

Comments
 (0)