-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Symbol resolution fails when importing code across compilation units #16
Comments
I do not remember if I chose symbols simply because I wanted to reduce property clutter in the objects they were attached to, or if I was just following a pattern I found WRT the initial implementation of reflect-metadata. Off the top of my head, your suggestion of switching to strings seems reasonable and good. I think I would probably rework the names a little (maybe the old school '_' prefix), and would probably want to define them as non-enumerable properties so that folks who might currently be iterating objects, don't suddenly find new properties they were not expecting. I'll take a deeper look this weekend. You obviously have a good grasp on the subject to have tracked this down, so if you have any thoughts on the above, please share. |
I can't take credit for finding the root cause--that was a colleague--though I did create failing examples for him to work with. :) Once he pointed out what was probably going on, I smacked my head, said "of course," and created this branch to solve my immediate need (the Good thought on checking libraries aside As for the names, I did in fact use the more pythonic I love how this library focuses on the asynchronous use case, and does so tersely. Thanks for responding so quickly! LMK if I can do something else to help |
Its been so long since I dug into the details, that I forgot the purpose of Reflect.setMetadata is to associate meta-data with something, not set data on it. So, not only is it safe to make these strings (as TypeScript itself does for I believe the theory is solid, and all the tests pass. Technically I suppose its a 'bug' fix, but going to push it shortly as a 'feature' release just because it does enable support for something that was not previously possible. |
In trying to use this library on a project that has a build with multiple output javascript files, I find that I am unable to inject or
get()
dependencies that were defined in a different context, even though during runtime I'm passing the DI Container and valid keys into the other context.It turns out that the library's internal constants are defined as symbols which are unique per execution context. Short of passing around the library objects (decorators, container, etc) and defining injectables inside closures or assigning them to globals at the beginning of each execution context, there's no way to share the container across compilation units in a way that doesn't fail to inject/get the dependencies.
One simple solution would be to change the constants to be defined as strings, and--in fact--that's what I do in my fork of this library, but I didn't want to open a PR before understanding if there might be another reason for the choice of
Symbol
for the internal constants?The text was updated successfully, but these errors were encountered: