Dependency injection without ts metadata #1080
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Esbuild doesn't support 'emitDecoratorMetadata' and doesn't intend to support it in the future: evanw/esbuild#257, evanw/esbuild#509. There is also no real hope that one could write an esbuild plugin that does the job in the near future: evanw/esbuild#111. Our current solution to run
typescript
on every module is slow and kind of defeats the purpose of esbuild.Thus, we migrate tsyringe nice concept to automatically recognize the type of the dependency (using the emitted metadata) to explicitly annotating each dependency with
@inject('Type')
. This is similar to https://github.com/inversify/InversifyJS/blob/master/wiki/classes_as_id.md.Things that one could still improve in the future:
@inject(AuthService)
injectSymbol
method to automatically register a symbol -> class alias so that we don't have to do this manually intsyringe.config
(there might be problems with circular imports if this approach is used).