microsoft / tsyringe

Lightweight dependency injection container for JavaScript/TypeScript
MIT License
5.19k stars 172 forks source link

Default values for @inject() #163

Open SirBernardPhilip opened 3 years ago

SirBernardPhilip commented 3 years ago

Even though there is already the registry, where we can set the providers for the injections. It was discussed in a not so recent issue that the possibility of having default or optional dependencies would be interesting. Since I have not seen it being implemented I came up with this simple first implementation. It does more or less the same that @registry() does but within the @inject() decorator, which will allow for simpler code I believe.

ghost commented 3 years ago

CLA assistant check
All CLA requirements met.

MeltingMosaic commented 2 years ago

Interesting. I think this is workable. Could you update the documentation?

SirBernardPhilip commented 2 years ago

Interesting. I think this is workable. Could you update the documentation?

Great! I have added an extra sentence to the inject() section. If you think it needs further explanation or even an example let me know.

RaulPROP commented 2 years ago

This would be awesome, any news on this?