AndroidKodeinSample icon indicating copy to clipboard operation
AndroidKodeinSample copied to clipboard

Provide View and inject in Presenter but retrieve different instance of View

Open hoangduchuu opened this issue 6 years ago • 2 comments

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!

hoangduchuu avatar Dec 16 '18 07:12 hoangduchuu

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.

JorgeCastilloPrz avatar Dec 16 '18 08:12 JorgeCastilloPrz

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

hoangduchuu avatar Dec 25 '18 07:12 hoangduchuu