Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to add specific instance of class to scope #277

Closed
miszmaniac opened this issue Oct 22, 2018 · 2 comments
Closed

Add method to add specific instance of class to scope #277

miszmaniac opened this issue Oct 22, 2018 · 2 comments
Labels
core status:checking currently in analysis - discussion or need more detailed specs
Milestone

Comments

@miszmaniac
Copy link

Is your feature request related to a problem? Please describe.
I had this problem when creating more advanced MVP example.
Sometimes you need to pass activity (which is scope owner) to for example UseCase.
Now you're forced not to use constructor injection, because you can't easily define injection of this activity.

Describe the solution you'd like
The best idea (which @arnaudgiuliani told me on slack!) would be to make a method inside scope addInstance() and just pass whatever it is inside scope, to be available with simple get().
This instance would have the same lifecycle as whole scope, to prevent leaks.

Describe alternatives you've considered
I've tried to use injection parameters, but this forces you to inject everything using lazy methods instead of constructors. In simplest case you end up with something like that:

    factory { (activity: AppCompatActivity) -> SampleKoinView(activity) }
    factory { (activity: SampleKoinActivity) -> SampleKoinPresenter(activity.presentedView, get()) }
    factory { (activity: SampleKoinActivity) -> TwoSimplePagesAdapter(activity.supportFragmentManager) }

Target Koin project
koin-core

@arnaudgiuliani arnaudgiuliani added core type:feature-proposal status:checking currently in analysis - discussion or need more detailed specs labels Oct 24, 2018
@arnaudgiuliani arnaudgiuliani added this to the 1.0.2 milestone Oct 24, 2018
@arnaudgiuliani
Copy link
Member

The Scope.addInstance function has been added to koin 1.0.2.

@freaksgit
Copy link

The Scope.addInstance function has been added to koin 1.0.2.

Hello!
Could you please tell is this added in koin 2.0?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core status:checking currently in analysis - discussion or need more detailed specs
Projects
None yet
Development

No branches or pull requests

3 participants