could be a new feature, but for now the better way...
# koin
a
could be a new feature, but for now the better way is to handle it with try catch
n
Yep, that's what I ended up doing:
Copy code
/**
 * Retrieve given dependency for KoinComponent
 * @param name - bean canonicalName
 * @param parameters - injection parameters
 */
fun <T : Any> KoinComponent.find(
		name: String = "",
		clazz: KClass<*>,
		scope: Scope? = null,
		parameters: ParameterDefinition = emptyParameterDefinition()
): T? =
		doFind { getKoin().get<T>(name, clazz, scope, parameters) }

fun <T : Any?> doFind(block: () -> T): T? {
	return try { block() } catch (e: NoBeanDefFoundException) { null }
}
a
yep
n
I definitely think this should be standard in the library. It makes variations in applications quite powerful, as entire features can be switched off no problem.
a
can make it part of the
Koin
API
not in KoinComponent