-
Notifications
You must be signed in to change notification settings - Fork 72
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
Fix: containers with common collaborator share resolved instances for their own definitions #169
Conversation
@ilyapuchka This fixes the original test where there's two isolated containers but the following test fails. a) There is a rootContainer When resolving password on both containers, the first one should pass and the second resolution should fail The two child containers are leaking into each other. The second container has access to the first containers registry.
|
@ilyapuchka Here's a second failure in the tests you applied Root Containers should not have access to their children's registry I added a check in the test you created:
I believe this is do to the change you made where adding a collaborator to yourself ALSO forces that to collaborate with you.
|
Thanks for adding those test cases, I'll take a look later. |
I agree, you did make it bidirectional in this commit, e7d8fb4 but I think that means we'll never have isolated containers. So I can see now that collaborations has a completely different use case. The wiki talks about Modules (good) but its clear now you didn't include isolation as a property of a module, since its bi directional. That is something I was expecting and rather counting on. My question stands: #168 How do you intend people to create isolated hierarchical containers? Or is that simply not supported? |
My vision on that is that you can not have everything (or we need to design a new feature). If your container collaborate their are connected into a bidirectional graph, and library goes around this graph to resolve instance. In in this graph there are several ambiguous definitions and there is a rout to both of them - there is no way to say what variant will be used (it depends on the order of containers references). In your case I would suggest either to use named definitions (for that you will need to store tag that represents state of your app, like loggedIn and notLoggedIn) and use tag to disambiguate your requests at runtime, or do not keep both containers around at the same time, but this will make you to recreate containers graph. We can also have a method to stop collaboration which can make this task easier. And somehow make bidirectional connection opt in instead of default. Also if you don't want collaboration to happen and return instance that you do not expect don't resolve component using container that did not register it. And you can always fallback to explicit calls to other containers from within registered factories instead of collaboration. Probably for complicated containers graphs its the best option. |
Resolves #168