sebastien.rouif
10/20/2020, 12:10 PMscoped { (mapId: String) -> MapIdProvider(mapId = mapId) }
but I need to call myScope.get { parametersOf(getMapId()) }
directly after the scope creation so that the mapId is passed to the bean definition. It seems that Scope
class can also have some parameters so I tried
koin.createScope<RootActivityScopeKey>().also {
it.addParameters(parametersOf(getMapId()))
}
but then I get Can't get injected parameter #0 from DefinitionParameters[] for type 'java.lang.String'
I tried removing the definition in the scope adding the
koin.createScope<RootActivityScopeKey>().also {
it.addParameters(parametersOf(MapIdProvider(getMapId())))
}
but no success either.
Is there a better way to inject that MapIdProvider
? note that MapIdProvider
is just a dataClass that holds the mapIdtynn
10/20/2020, 12:22 PMcreateScope(id, source)
and provide the mapId
as source there. Then it should be possible to crate the MapIdProvider as scoped { MapIdProvider(mapId = getSource()) }
sebastien.rouif
10/20/2020, 1:51 PMsebastien.rouif
10/20/2020, 1:52 PM@Suppress("UNCHECKED_CAST")
private fun <T : Any> resolveInstance(
qualifier: Qualifier?,
clazz: KClass<T>,
parameters: ParametersDefinition?
): T {
if (_closed) {
throw ClosedScopeException("Scope '$id' is closed")
}
val indexKey = indexKey(clazz, qualifier)
return _instanceRegistry.resolveInstance(indexKey, parameters)
?: run {
_koin._logger.debug("'${clazz.getFullName()}' - q:'$qualifier' not found in current scope")
getFromSource(clazz)
}
?: run {
_koin._logger.debug("'${clazz.getFullName()}' - q:'$qualifier' not found in current scope's source")
_parameters?.getOrNull<T>(clazz)
}
?: run {
_koin._logger.debug("'${clazz.getFullName()}' - q:'$qualifier' not found in injected parameters")
findInOtherScope<T>(clazz, qualifier, parameters)
}
?: run {
_koin._logger.debug("'${clazz.getFullName()}' - q:'$qualifier' not found in linked scopes")
throwDefinitionNotFound(qualifier, clazz)
}
}
sebastien.rouif
10/20/2020, 1:52 PMtynn
10/20/2020, 2:02 PMsource
is cleaner and a bit more generic.sebastien.rouif
10/20/2020, 3:24 PM