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

Inject empty array with @injectAll() in case of unregistered string or symbol token #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

paztek
Copy link

@paztek paztek commented Nov 16, 2019

Closes: #63

This PR introduces the following breaking change:

When using @injectAll('myToken') private foo: Foo[] and when nothing is registered for the specified token, it will inject an empty array instead of throwing an "Attempted to resolve unregistered dependency token: ${token.toString()}" error.

This is a breaking change because things that used to break (throwing an error) won't break anymore.

Also, it keeps the same behavior as before when the token is a class constructor and an array of a single instance of the class is injected.

@msftclas
Copy link

msftclas commented Nov 16, 2019

CLA assistant check
All CLA requirements met.

Copy link
Collaborator

@Xapphire13 Xapphire13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting on the changes discussed in #63

@etiennenoel
Copy link

Any ways I can help and unblock this PR? @Xapphire13 I know it's been a while, do you know if you remember the changes you were waiting on?

@MeltingMosaic
Copy link
Collaborator

MeltingMosaic commented Jun 16, 2021

I think the change required was to make it so that the new behavior is not breaking. The idea of an @optional() decorator or being able to pass in a default value to @injectAll() could work. Thinking about it right now, I think the simplest solution would be to do something like @injectAll({defaultValue:[]}). What do you think @Xapphire13 ?

@stemyke
Copy link

stemyke commented Jun 28, 2021

I am just looking today for the same feature. I think the @optional() decorator would be great.

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.

Inject an empty array with @injectAll() when nothing registered for the token
6 participants