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

Make shared component scope default #110

Closed
ilyapuchka opened this issue Aug 14, 2016 · 4 comments
Closed

Make shared component scope default #110

ilyapuchka opened this issue Aug 14, 2016 · 4 comments
Milestone

Comments

@ilyapuchka
Copy link
Collaborator

In most cases when resolving objects graph we want different consumers of the same service to have a reference to the same instance of that service instead of having unique instances. Then shared components scope makes more sense as a default value.

@devandanger
Copy link

@ilyapuchka I'm curious as why this is the default scope returned. Feels like this opt-ins to implicit state which can be difficult to reason with when there are issues with the state of those instances. I could also make arguments to where UTs could become flaky or difficult to also reason with.

This is purely a thought exercise, just curious if you had an experiences with this occurring.

@ilyapuchka
Copy link
Collaborator Author

It seems to me that this is the most common scope, it's rear when you really need unique objects in the graph or those objects have only single reference so there is no difference between shared and unique scopes for them.

@devandanger
Copy link

Maybe I'm misunderstanding it let me try and clarify my own mental model of it...
Say you have navigation stack where you have VC's A, B
VC A gets an instance of type Foo and sets a field in it to "Bar"
VC B gets pushed on the stack and grabs an instance of Foo as well.
Given both these instances of Foo are injected/resolved through Dip used the default/shared scope.
Could we expect VC B's instance of Foo have this field set to Bar at this point as well?

@ilyapuchka
Copy link
Collaborator Author

Yes, they will share the reference to the same object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants