tsyringe icon indicating copy to clipboard operation
tsyringe copied to clipboard

Move ctor param info from global map to metadata. Fixes #161

Open florian-g2 opened this issue 2 years ago • 5 comments

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

florian-g2 avatar Jun 28 '22 20:06 florian-g2

CLA assistant check
All CLA requirements met.

ghost avatar Jun 28 '22 20:06 ghost

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

florian-g2 avatar Jun 28 '22 20:06 florian-g2

Hey @Xapphire13 @MeltingMosaic, any chances this could get merged?

florian-g2 avatar Sep 23 '22 12:09 florian-g2

Definitely would like to get this merged in.

endurance avatar Nov 29 '22 17:11 endurance