AndroidKodeinSample
AndroidKodeinSample copied to clipboard
Provide View and inject in Presenter but retrieve different instance of View
Hi Jorge, Trying to provide and want to retrieve the singleton instance of View. But can not retrieve the singleton instance. How can I provide view using Koin instead of assign in BasePresenter class This is my Module https://github.com/hoangduchuu/koin-injection/blob/feature/FRAGMENT_SCOPE/app/src/main/java/grabteacher/com/presentation/timelines/timeline/di/MainModule.kt
Thanks, Jorge!
I'm not convinced about why would you want to do that, since the View should just be used from inside your Presenter / ViewModel.
If we assume your mode is okay and go with it, you'd just need to use a standard provider instead of a singleton, since the instance returned will always be the one you passed when constructing the module.
Note that this is dangerous since you'd need to rebind the new view every time your activity gets recreated by a config change or whatever, and with your approach that means you would need to rebuild your activity DI graph.
Because, in some hours, In FragmentPresenter I need to use ActivityPresenter or ActivityView. Then I need to provide View by Koin instead of pass the View into constructor