Permit overwrite and reset from child capsule #4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adding a new dependency of an already existing type should reset the initialization of all dependencies that depend on that class/interface/type so they can be re-resolved with the new dependency for that type.
This test is a good example of something that is now possible that wasn't before:
Previously, the last assertion in the test would fail, since the GreeterService would already been initialized once with the first Greeter implementation
FirstImpl
. Registering a second implementation of the same type in a child capsule would not have had any affect.This made it very cumbersome when you had tests that would utilize all but a few of the real dependencies that you would normally use at runtime. By changing so whenever a new (child) capsule was greeted, all inherited dependencies that had already been initialized would be reset, and they would also consider registered dependencies in the child module when instantiating this type.
With this change it would be very easy to change resolved dependencies of classes in retrospective, which means less boiler plate when creating tests where most dependencies are not simple mocks or stubs.