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
The first and most annoying problem is that decorators have to be added to everything. This makes your code "semi"-dependent on Inversify in the sense that if you want to change dependency system you have to change each and every file that has dependency injection.
Interfaces are a no go. You can't use interfaces for their intended use case. You have to either use abstract classes instead of interfaces, or you have to add a @inject(IDENTIFIER) before your parameter and then in the config you bind everything to that identifier and not the interface. And again this comes back to the first point of decorators.
I've been trying to solve these two issues and had decent success (with help of custom transformers). I've been able to completely eliminate the first issue. All the metadata that Inversify needed are now resolved on compile-time. The second issue with interfaces are almost completely fixed. In TypeScript you can't pass an interface as an argument which makes it a bit annoying. The workaround is that I've created a method called InterfaceSymbol<I>(), This method doesn't actually exists, but is a placeholder for the compiler to read the type I (the interface) and replace the method call with Symbol.for("SHA256"). So when writing the config file the compiled code will look something like this:
In conclusion I will replace Inversify with my own dependency system: ts-di-transformer. Hopefully all goes well and if I find things that's missing I will just try to implement these features into the DI.
The text was updated successfully, but these errors were encountered:
I have two problems with Inversify.
@inject(IDENTIFIER)
before your parameter and then in the config you bind everything to that identifier and not the interface. And again this comes back to the first point of decorators.I've been trying to solve these two issues and had decent success (with help of custom transformers). I've been able to completely eliminate the first issue. All the metadata that Inversify needed are now resolved on compile-time. The second issue with interfaces are almost completely fixed. In TypeScript you can't pass an interface as an argument which makes it a bit annoying. The workaround is that I've created a method called
InterfaceSymbol<I>()
, This method doesn't actually exists, but is a placeholder for the compiler to read the typeI
(the interface) and replace the method call withSymbol.for("SHA256")
. So when writing the config file the compiled code will look something like this:In conclusion I will replace Inversify with my own dependency system: ts-di-transformer. Hopefully all goes well and if I find things that's missing I will just try to implement these features into the DI.
The text was updated successfully, but these errors were encountered: