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

NewInstance: register default instance before new instance (fixes #197) #198

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

krisdages
Copy link

@krisdages krisdages commented Feb 22, 2020

#197

(Edit)

I looked into the implementation and found what I think is a reasonable fix to keep the default singleton behavior for undecorated injections while still allowing new instances to be added to an array strategy:

If there is no resolver for the NewInstance key, auto-register the key before calling container.registerInstance with the new instance.

I'm only calling autoRegister if the new instance key is a function; i'm not sure exactly what the expected behavior would be if the key is a primitive. There is also a type assertion that the key is a
constructor; makes me a little uncomfortable, but I see that same type assertion elsewhere in the
container, so I think it's consistent in that regard.


(Original): Failing tests only

I started by adding some tests that were more similar to my actual use case
before realizing the actual difference between the working tests and the failing case.

The distilled failing test case here is:
new instance of a dependency does not become the default instance in the container

For the existing tests, swapping the order of getting App1 and Logger causes all of the NewInstance tests to fail.

PR is just for info purposes unless you want to add these extra tests.
Also, my editor kept changing line endings to CRLF, realized the wrong value was in .editorconfig

…get(Dep)`

I started with some tests that were more similar to my actual use case
 before realizing the difference between the working tests and the failing case.

The distilled failing test case here is:
 `new instance of a dependency does not become the default instance in the container`

For the existing tests, swapping the order of getting App1 and Logger causes all of the NewInstance tests to fail.
@krisdages krisdages changed the title Failing tests for #197 NewInstance: register default instance before new instance (fixes #197) Feb 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant