How to inject viewModel in BaseFragment in Koin
See original GitHub issueI have created an abstract BaseFragment class which will be extended by other concrete Fragment classes. I want to inject ViewModel in my BaseFragment using Koin. Here is my BaseFragment:
abstract class BaseFragment<out VM : BaseViewModel, DB : ViewDataBinding>(private val mViewModelClass: Class<VM>) : Fragment() {
val viewModel: VM by viewModel()
open lateinit var binding: DB
fun init(inflater: LayoutInflater, container: ViewGroup) {
binding = DataBindingUtil.inflate(inflater, getLayoutRes(), container, false)
}
open fun init() {}
@LayoutRes
abstract fun getLayoutRes(): Int
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View {
init(inflater, container!!)
init()
super.onCreateView(inflater, container, savedInstanceState)
return binding.root
}
open fun refresh() {}
}
But I am not able to do so. I am using 2.0.1 version of Koin
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How to inject viewModel in BaseFragment using Koin
I want to inject ViewModel in my BaseFragment using Koin . Here is my BaseFragment: abstract class BaseFragment<out VM : BaseViewModel, ...
Read more >Android ViewModel & Navigation | Koin
ViewModel class. You can specify how you inject the constructor of the class and use the get() function to inject dependencies.
Read more >How to inject viewModel in BaseFragment using Koin-kotlin
Add your ViewModel as an abstract and set value when you extend your BaseFragment. My BaseFragment have: abstract class BaseFragment<Binding ...
Read more >Dependency Injection using Koin - Medium
Koin is the dependency injection framework purely built in Kotlin. ... class LandingFragment : BaseFragment() { //View model injection using ...
Read more >Dagger2 injection doesn't happen when the ... - Reddit
Hi there, My app has a BaseFragment where I intend to keep all ... the ViewModel to the NavBackStackEntry of that nested navigation...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Something like this?
@SAGARSURI you can see this Cannot resolve viewModel injection with delegate style declaration