I want to use koin to create a small library that ...
# koin
m
I want to use koin to create a small library that includes some android UI - for this I would want to inject dependencies into viewmodels used by such UI. (Yes this library will be quite opinionated and not expected for generic reusability) I found this on context isolation, but I’m not sure how to use this with functions such as
koinViewModel()
. Any suggestions on how to go about this?
Copy code
@OptIn(KoinInternalApi::class)
@Composable
inline fun <reified T : ViewModel> myKoinViewModel(
    qualifier: Qualifier? = null,
    owner: ViewModelStoreOwner = checkNotNull(LocalViewModelStoreOwner.current) {
        "No ViewModelStoreOwner was provided via LocalViewModelStoreOwner"
    },
    scope: Scope = MyKoinContext.koinApp!!.koin.scopeRegistry.rootScope,
    noinline parameters: ParametersDefinition? = null
): T {
    return getViewModel(qualifier, owner, scope, parameters)
}
This seems to work, but it requires my library/sdk to opt in to KoinInternalApi, which doesn’t feel great? 🤔
@arnaud.giuliani sorry for the ping, but im very curious if you have any input on this 🙏
a
Compose & Scope/Context are not well defined for now. You need to resolve against your Koin context and not the default one