aipok
09/07/2020, 9:11 AMScopeActivity and ScopeFragment API’s…
• While using shared instance for activity and share it to all the fragments, it is not clear how to instantiate sharedViewModel inside fragments that was created by activity. Looks like this API is not available anymore. I was able to achieve same result by using
scopeActivity?.let {
viewModel = it.getViewModel<SomeViewModel>()
}
is that the way to do this now?
• Another pain point is to inject instances using scopeActivity into lazy properties. They are became nullable by default. Is it might be possible to use Fragment’s requireActivity() method for getting requireScopeActivity which is not nullable. Otherwise I have to insert ? everywhere in my code then using property initialized like this
protected val imm by lazy {
scopeActivity?.get<InputMethodManager> {
parametersOf(requireActivity())
}
}
• In order to instantiate something that do not require scope from ScopeActivity or ScopeFragment should I use GlobalContext or ScopeActivity.koin calls? It is a bit confusing that default get or inject in ScopeActivity and ScopeFragment subclasses are trying to get instance from its scope . From what I have, usually I’m getting some factory instances by default without any scope and some specific (more like a rare) scoped injections. I would prefer to have scope.get / scope.inject and default get / inject to be koin.get koin.inject . Not sure might be thats only my opinion and other developers are using it opposite.
Fill free to open discussion and drop your comments. I would happy to hear any suggestions or ways to use Koin scope system or sharedViewModel definition.
Thanks!arnaud.giuliani
09/09/2020, 1:10 PM