Dynamic parameter injection
See original GitHub issueI’m using the koin-android-architecture
version of the library. I’ve come across a situation where I’d like to use a parameter determined when an Activity/Fragment is created for a ViewModel. As an example:
SomeActivity.kt
class SomeActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val id = getIdExtra() // From intent
TODO("use id")
val viewModel = getViewModel<SomeViewModel>()
// ...
}
}
SomeViewModel.kt
class SomeViewModel(
private val repository: Repository, // Singleton
private val id: Long
) : BaseViewModel() {
// ...
}
Is there a good way of doing this? I know that Kodein has factory bindings, so I was wondering if there was something similar.
This issue is similar to #6 but I was wondering if there was a better method of achieving this now since that issue is relatively old.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Dependency injection with dynamic parameter - Stack Overflow
The problem I have is that I wanted to inject Request so that I could change the library I was using and it...
Read more >How to deal with dependency injection with dynamic ...
Let's say I have a class that requires some parameters in the constructor: class SomeClass { public function __constructor(AnotherClass $cls) {.
Read more >Dynamic dependency injection by pwm - GitHub Pages
In this short article I would like to demonstrate a way to inject dependencies that are not known until runtime. There are many...
Read more >Dynamic injection molding parameters used in this study.
In this paper, a numerical dynamic injection molding technology (DIMT) is presented, which is based on the finite element (FE) method. This numerical...
Read more >How to fix SQL injection flaws for dynamic parameters
View This Post. STambade077368 (Customer) asked a question. March 8, 2022 at 7:16 AM. How to fix SQL injection flaws for dynamic parameters....
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
Hi there! How is it going in 2.0?
I 've add Koin parameters to release 0.9.0.
you will be able to use parameters in your definition. Given class:
We can use parameters to be injected with
by inject()
Injecting the parameter:
stay tuned👍