view Model With Saved State Handle
Returns a Lazy property delegate to access the AppCompatActivity's ViewModel, which will be obtained from a Kodein DI factory with a SavedStateHandle argument.
class MyAppCompatActivity : AppCompatActivity(), DIAware {
override val di: DI by closestDI()
private val viewmodel: MyViewModel by viewModelWithSavedStateHandle()
}Parameters
Extension function applies to AppCompatActivity which implements DIAware
The type of ViewModel to obtain
The bound Kodein DI tag
Throws
if accessed before the AppCompatActivity is attached to the Application
If no factory was found.
When calling the factory, if the value construction triggered a dependency loop.
Returns a Lazy property delegate to access a ViewModel by default scoped to this Fragment, which will be obtained from a Kodein DI factory with a SavedStateHandle argument.
class MyFragment : Fragment(), DIAware {
override val di: DI by closesDI()
private val viewmodel: MyViewModel by viewModelWithSavedStateHandle()
}Default scope may be overridden with parameter ownerProducer:
class MyFragment : Fragment(), DIAware {
override val di: DI by closestDI()
private val viewmodel: MyViewModel by viewModelWithSavedStateHandle(ownerProducer = { requireParentFragment() })
}Parameters
Extension function applies to Fragment which implements DIAware
The type of ViewModel to obtain
Optionally override the default ViewModel owner
The bound Kodein DI tag
Throws
if accessed before this Fragment is attached
If no factory was found.
When calling the factory, if the value construction triggered a dependency loop.