How to define third-party dependency in TypeDI or Inversify

584 views Asked by At

I am looking into using Dependency Injection for a TypeScript/Node project, which is a new language/framework for me. TypeDI and Inversify came up as options, but I couldn’t figure out in either case how to tell the container how to create an instance of a library/module class.

For example, I would like to tell the DI container how to instantiate a class from a third-party library such that I can simply supply object of that type as a parameter of to one of my classes.

However in both TypeDI and Inversify, it seems like the only annotations are for my own class. So how do tell the container how do instantiate dependencies where I don’t have direct access or control to the underlying source code?

1

There are 1 answers

0
Jed On BEST ANSWER

Cross-posting the answer I got in the TypeDI GitHub repo:

You could do Container.set(SQS, new SQS(…)) on app initialization, then the DI will know what to inject.