sjs-dideprecated

DI

Usage no npm install needed!

<script type="module">
  import sjsDi from 'https://cdn.skypack.dev/sjs-di';
</script>

README

sjs-di

Very simple dependency injection

Installation

$ npm install sjs-di

Lets DI

Prepare

repository.js

import {Inject, Container} from 'sjs-di';
import {HttpClient} from 'some-http-client';


@Inject(HttpClient)
class Repository {
    constructor(http){
        //...
    }
    async getUsers(){
        //...
    }
}

@Inject(Repository)
class Users {
    constructor(repo){
        //...
    }
}

@Inject(Users)
class App {
    constructor(users){
        //...
    }
}

let container = new Container();
container.registerInstance(HttpClient, new HttpClient('/api'))
let app = container.get(App);

Running tests

$ npm test

License

MIT