typedi
typedi copied to clipboard
Support Symbol for container id
Description
Container.of used to accept instanceId of any. Now it only accepts string (see this commit: https://github.com/typestack/typedi/commit/511e37f29e7fce4759058cfc5d7acb297bf4a653). Shouldn't it also support Symbol or Token to prevent name clashes?
Proposed solution
Should be able to do Container.of(Symbol('my-container'))
Yes, it was simplified to allow easier internal workings. Why using string IDs doesn't work for you?
If two parts of an app use the same string without knowing, you'll get a clash. While if they encapsulate it with a Symbol you won't.
See this article for more info: https://blog.thoughtram.io/angular/2016/05/23/opaque-tokens-in-angular-2.html
Article is focused on Angular dependency injection but the jist of it is the same.
This is added in https://github.com/typestack/typedi/commit/0c0dcab672bdba8a064400a8d7a063d3e1fc6bdf and will be included in the next release.