Skip to content

Instantly share code, notes, and snippets.

@qwert2603
Last active August 7, 2021 16:58
Show Gist options
  • Save qwert2603/a7ec80a0f52ed5fadda2d5ba3bfa439e to your computer and use it in GitHub Desktop.
Save qwert2603/a7ec80a0f52ed5fadda2d5ba3bfa439e to your computer and use it in GitHub Desktop.
inline fun <reified K, reified V> Module.intoMultibinding(key: K, value: V) {
var multibinding: Multibinding<K, V>? = null
single(
qualifier = named("${K::class.getFullName()}_${V::class.getFullName()}_$key"),
createdAtStart = true,
) {
multibinding = get(multibindingQualifier<K, V>())
multibinding!![key] = value
}.onClose {
multibinding?.remove(key)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment