Forwarding parameters
See original GitHub issueKoin 0.9.0 is really great Thanks for the parameter support when injecting dependencies. It is working great.
I have a small optimization for injecting with parameters. It would be fantastic if we can forward this parameter map.
e.g.
class MyActivity : Activity() {
val presenter: MyPresenter by inject(parameters = mapOf("activity" to this)
}
class MyPresenter(navigator: Navigator) {
}
class Navigator(activity: Activity) {
}
and the module looks like this
val myModule: Module = applicationContext {
context("Screen") {
bean { params -> MyPresenter(get()) } // here we have the params with the activity
bean { params -> Navigator(params["activity"]) } // BUT the activity is needed here (and here are params null)
}
}
can you provide us with the possibillty to forward these params in the get() method, e.g
val myModule: Module = applicationContext {
context("Screen") {
bean { params -> MyPresenter(get(params)) } // forward params in get(params)
bean { params -> Navigator(params["activity"]) } // so we can access the params here
}
}
looking at the get() functions it should be possible in the current version 0.9.0 you pass an emptyMap to the resolve functions.
inline fun <reified T : Any> get(): T = koinContext.resolveByClass(emptyMap())
inline fun <reified T : Any> get(name: String): T = koinContext.resolveByName(name, emptyMap())
maybe we can do something like this:
inline fun <reified T : Any> get(parameters: ParameterMap = emptyMap()): T = koinContext.resolveByClass(parameters)
inline fun <reified T : Any> get(name: String, parameters: ParameterMap = emptyMap()): T = koinContext.resolveByName(name, parameters)
What do you think about this?
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
std::forward - cppreference.com
This example demonstrates perfect forwarding of the parameter(s) to the argument of the constructor of class T . Also, perfect forwarding of parameter...
Read more >Configuring forwarding parameters
Configuring forwarding parameters. The following configurable parameters control the forwarding behavior of HP routing switches:.
Read more >URL Redirect with Parameters - Domains - Namecheap.com
URL Redirect with Parameters. You can use URL Redirect to forward your visitors to a specific page at the destination URL and pass...
Read more >URL Redirect parameters · Cloudflare Rules docs
Create rules that adjust incoming requests, change Cloudflare settings, or trigger actions.
Read more >C++ static code analysis: "Forwarding references" parameters ...
"Forwarding references" parameters should be used only to forward parameters ... Forwarding references are a special kind of references that both ignore and ......
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
I’ve got it working now by using
Such an example should still be put on the website though. Thanks for creating Koin!
Hello. (while waiting for my kotlin slack invitation I’m writing here)
I have the following module defined:
and getting called by
The problem before adding all the
params ->
was that the “downstream dependencies” didn’t get the requiredSingleSignOnAccount
instance and Koin failed to inject. Now I think I just need to pass the params object through theprovideRetrofit
line (so it reaches theprovideAuthenticationInterceptor
) but with the extra(acc: SingleSignOnAccount)
parameter I don’t know the syntax to make this working.I got the
params -> ... get { params }
from here and it would also be nice if such an example was on the website.