Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import 'reflect-metadata'
  2. import {Container, Inject, Service} from "typedi";
  3.  
  4. @Service()
  5. export class Bla {}
  6.  
  7. const testconfig = {}
  8. type ConfigType = typeof testconfig
  9.  
  10. @Service()
  11. export class Base {
  12. public constructor(
  13. @Inject('config')
  14. protected cfg: ConfigType, //This is not injected
  15. protected bla: Bla // if this is coming from a module w/ import 'reflect-metadata'
  16. ) {
  17. if(!cfg){
  18. throw Error('expected typedi to inject cfg')
  19. }
  20. console.log('cfg injected')
  21. }
  22. }
  23.  
  24. @Service()
  25. export class Child extends Base {}
  26.  
  27.  
  28. if (require.main === module) {
  29. Container.set('config', testconfig)
  30. Container.get(Base) //works
  31. Container.get(Child) //inherited constructor does not receive a named dependency
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement