You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! I found this library via your comment on tysringe. Constructor injection is the most common form of dependency injection but from what I can tell, this library does not support it. Can you confirm whether or not this library supports constructor injection, and if not, is that a design decision or a feature you plan to implement in future? I think, for people coming from tsyringe, it would be very helpful to clarify the compatibility. Thank you :)
This pattern is not supported because it requires TypeScript-only feature flag emitDecoratorMetadata together with legacy reflect-metadata to collect the runtime information of the parameters.
This pattern is not supported for now, because the latest Stage 3 proposal tc39/proposal-decorators (introduced in TS 5) does not support decorating parameters yet:
Once we have validated this core approach, the authors of this proposal plan to come back and make proposals for more kinds of decorators. In particular, given the popularity of TypeScript parameter decorators, we are considering including parameter decorators in this proposal's initial version.
If the proposal changes in the future, I will follow up to implement the missing features.
So it is a design decision to follow the standardization and not to introduce legacy dependencies.
But you can always use the inject() function in constructors:
classSomeService{constructor(dep=inject(SomeToken)){// inject() can be used anywhere during construction}}
Thank you for the quick answer, I appreciate it :)
The idea of sticking with features that are available in Javascript, rather than through packages, is a great idea. Unfortunately, I think that means, at least for now, this package is not offering dependency injection: the inject function is not actually dependency injection, it is a service locator. There's a great Martin Fowler piece which compares a service locator to dependency injection and provides pros vs. cons for each ("Inversion of Control Containers and the Dependency Injection pattern").
For now, I'll stick with tsyringe, but keep an eye on this project, hopefully parameter decorators make it into Javascript someday soon!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi! I found this library via your comment on tysringe. Constructor injection is the most common form of dependency injection but from what I can tell, this library does not support it. Can you confirm whether or not this library supports constructor injection, and if not, is that a design decision or a feature you plan to implement in future? I think, for people coming from tsyringe, it would be very helpful to clarify the compatibility. Thank you :)
Beta Was this translation helpful? Give feedback.
All reactions