tsyringe
tsyringe copied to clipboard
Inject empty array with @injectAll() in case of unregistered string or symbol token
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.
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?
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 ?
I am just looking today for the same feature. I think the @optional() decorator would be great.