view Model
Returns a Lazy property delegate to access the AppCompatActivity's ViewModel, which will be obtained from a Kodein DI provider.
class MyAppCompatActivity : AppCompatActivity(), DIAware {
override val di: DI by closestDI()
private val viewmodel: MyViewModel by viewModel()
}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 provider was found.
When calling the provider, 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 provider.
class MyFragment : Fragment(), DIAware {
override val di: DI by closesDI()
private val viewmodel: MyViewModel by viewModel()
}Default scope may be overridden with parameter ownerProducer:
class MyFragment : Fragment(), DIAware {
override val di: DI by closestDI()
private val viewmodel: MyViewModel by viewModel (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 provider was found.
When calling the provider, if the value construction triggered a dependency loop.