tsyringe
tsyringe copied to clipboard
Move ctor param info from global map to metadata. Fixes #161
Hi there.
This PR moves the paramInfos acquired by the injectable()
decorator from the global typeInfo map to constructor/class metadata.
That fixes a TypeInfo not known for ...
bug occurring in an environment where a library with injectable dependencies is linked using symlinks (npm-link).
In this special environment, globals are not shared between the library and the main project, therefore the typeInfos populated by the injectable() decorator weren't accessible before to the main project.
Due to this unfavorable side-effect of the npm-link, the registry()
and autoInjectable()
decorators will still be broken because their functionalities require direct access to the global container instance.
Minimal repo reproducing the issue in the initial commit: https://github.com/florian-g2/npm-link-missing-globals
Another important note to take here is that no reflection polyfill is allowed to be imported inside the linked library. This would lead to the same fact that the polyfills also use a global map to store the metadata.
If reflection methods are required by the library itself, the types can be declared like in https://github.com/rbuckton/reflect-metadata/blob/master/Reflect.d.ts
Hey @Xapphire13 @MeltingMosaic, any chances this could get merged?
Definitely would like to get this merged in.