vue-di-container
Dependency injection container for Vue (especially class components).
Installation
npm install vue-di-container
Register the plugin:
; Vue.useVueDiContainer;
Usage
Keys
Injectable dependencies are identified by keys. Key is either a class function
or an instance of Token<T>
. Note that Typescript interfaces will not work.
Defining services
To define injectable service class, use @Service
decorator. When container
instantiates it, it will inject all constructor arguments (based on declared
parameter type or key provided with @Inject
decorator) as well as properties
marked with @Inject
.
; ;
Providers
What actually will be injected into services and components is determined by defined providers. Provider are set in component's options and are inherited by child components (and only them). Services are constructed lazily, only when needed.
Services that need to be available to all components should be set in Vue root:
new Vue.$mount'#app';
Injecting into components
Only property injection is supported on component classes. Alternatively, there is an option for this.
// or
License
MIT, see LICENSE.