[Vuejs]-Implementing dependency injection using Vue and Typescript

0👍

inject, etc. decorators cannot be used with component class. The use of decorators assumes that the class is instantiated by Inversify injector, while component class is instantiated by Vue framework, so a parameter that is provided to component constructor won’t be an instance of AuthService. This is what type error warns about.

The same problem is applicable to React components or any other framework that doesn’t use Inversify internally.

Inversify container should be accessed manually:

authService: AuthService = container.get(AuthService)

Since Vue already provides DI, it may be more convenient to use its own DI instead of third-party library like Inversify.

0👍

You could try to use this one vue-injector

Leave a comment