di-decorator-js

1.0.3 • Public • Published

Javascript - Dependency Injection Decorator

Simple Dependency Injection Decorator for javascript

Required: babel-plugin-transform-decorators-legacy in your project...

install npm i -D di-decorator-js or yarn add di-decorator-js

example

// file: my.provider.js
 
import { Injectable }  from 'di-decorator-js';
 
@Injectable({
    providers:[]
})
export class MyProvider {
    result() {
        return 'Eureka!';
    }
}
// file my.component.js
import { Injectable }  from 'di-decorator-js';
import { MyProvider } from './my.provider';
 
@Injectable({
    providers:[ MyProvider ] // must be the same order as the class constructor
})
class MyComponent {
    constructor(provider) {
        this.myProvider = provider;
    }
 
    resolve() {
        console.log(this.myProvider.result()); // out: 'Eureka!'
    }
}

Package Sidebar

Install

npm i di-decorator-js

Weekly Downloads

1

Version

1.0.3

License

Apache 2.0

Unpacked Size

19.8 kB

Total Files

6

Last publish

Collaborators

  • devcopie