typedi icon indicating copy to clipboard operation
typedi copied to clipboard

Support Symbol for container id

Open hisham opened this issue 4 years ago • 4 comments

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'))

hisham avatar Feb 03 '21 23:02 hisham

Yes, it was simplified to allow easier internal workings. Why using string IDs doesn't work for you?

NoNameProvided avatar Feb 13 '21 19:02 NoNameProvided

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.

hisham avatar Feb 17 '21 04:02 hisham

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.

hisham avatar Feb 17 '21 04:02 hisham

This is added in https://github.com/typestack/typedi/commit/0c0dcab672bdba8a064400a8d7a063d3e1fc6bdf and will be included in the next release.

NoNameProvided avatar Feb 21 '21 14:02 NoNameProvided