3.0.6 • Published 4 years ago

static-inject v3.0.6

Weekly downloads
17
License
ISC
Repository
github
Last release
4 years ago

static-inject

Simple dependency injector container.

instalation

npm install static-inject yarn add static-inject

Sample

Also see src/test.ts

import { Container } from 'static-inject';

// define interface as classes (in order to have a compiled names)
class Port {
    lower(text : string) : string { throw 'Not implemented' }
}

@adapter(Port)
class Adapter implements Port {
    lower(text: string): string {
        return text.toLowerCase();
    }
}

class Library {
    @port(Port)
    private port! : Port;

    test(){
        if (this.port.lower("UPPER") != "upper"){
            throw new Error("Test failed");
        }
        console.log("Test passed");
    }
}

Container.register(Adapter);
// or
Container.registerAs(Adapter, Port.name);
// or
Container.registerAs(Adapter, "Port");

const lib = new Library();
lib.test();
3.0.6

4 years ago

3.0.5

4 years ago

3.0.4

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago