Inject Activity
See original GitHub issueHi,
Koin is awesome but I’m having an issue. Some libraries, like Firebase Analytics, depend on the current Activity to perform some actions like setting a current screen.
class Analytics(private val activity: Activity) {
private val firebaseAnalytics: FirebaseAnalytics = FirebaseAnalytics.getInstance(activity)
fun setCurrentScreen(screenName: String) {
firebaseAnalytics.setCurrentScreen(activity, screenName, null)
}
}
class MainPresenter(analytics: Analytics) {
}
class MainActivity : AppCompatActivity() {
val presenter : MainPresenter by inject()
}
Is this possible with Koin? If yes, then I don’t see how.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:17
- Comments:30 (11 by maintainers)
Top Results From Across the Web
Inject activity using dagger - java - Stack Overflow
This way Dagger can create a singleton Picasso instance. The ReAdapter is annotated with @Inject (using constructor injection) so Dagger knows ...
Read more >Using Dagger in Android apps
To inject an object in the activity, you'd use the appComponent defined in your Application class and call the inject() method, passing in...
Read more >How to use Android Injector for Activity and Fragment objects ...
How to use Android Injector for Activity and Fragment objects through ... We can use AndroidInjection.inject(this) in activity after inject ...
Read more >Dagger: When to Inject for Activity and Fragment - Sangsoo Nam
For the dependency injection on Activity and Fragment , Dagger supports a helper method, AndroidInjection.inject() . Once it is called, ...
Read more >Dagger & Android Thoughts: Dependency Injection in Android
From the Dagger documentation — Many Android framework classes are instantiated by the OS itself, like Activity and Fragment. You have to perform...
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 am using
parameters
like below @westonal.LocationModule.class
MainActivity.class
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👍