Closed sebastian-zarzycki-apzumi closed 7 years ago
We need to add a feature for this. We have already an issue https://github.com/inversify/InversifyJS/issues/489. Please keep en eye on that issue to find the implementation progress.
Thanks for answer. My underlying question, though, was: how do I proceed for now, without this feature being implemented?
I'm afraid that because React only works with @lazyInject
and you are using babel this issue is a blocker. There is no way to get around it for now. I will try to implement that feature for you. I was going to pick a couple of tasks from the backlog this week so I will pick #489 first. I'm sorry but that is the best I can do to help you at the moment.
Thank you, I sure do appreciate this!
I'm operating in React stack, using Babel (ES2015 preset and some stage-0 things, decorators, etc). I'm having a hard time figuring out how to inject properties. I am able to create container, specify bindings. mark class as @injectable and when pulling dependencies straight from the container, it's fine. But how do I specify ES6 class and mark its properties as injectable? I've tried @lazyInject, but also to no avail. I know that part of the issue is that ES6 class doesn't really have properties defined in other place than constructor, but I saw other decorators (namely: type definitions from pleerock/class-transformer) somehow getting away with it using this syntax:
If I get this right, this syntax is then compiled to go into constructor anyway. (see example here)
I've seen some examples using vanillajs, but they all rely on injecting into constructor parameters, using index, which seems inelegant to say the least. There's no example using ES6 decorators or injecting property by name, not by index.
Is it possible to use decorators somehow to work around this, with @inject or @lazyInject?