简体   繁体   中英

How to define third-party dependency in TypeDI or Inversify

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM