1.0.8 • Published 8 years ago

@thatsmrtalbot/ioc v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
8 years ago

Build Status

Typescript IoC

Simple ioc for node & typescript

Usage

There are two methods "register" and "instance".

Register

Register registers an instance of a class against its constructor or a symbol.

For example registering against a constructor:

class Example {
    constructor() {
        // Nothing to do
    }
}

ioc.register(Example, new Example());

And registering against a symbol:

const ExampleSymbol = Symbol("Example");

ioc.register(ExampleSymbol, new Example());

Instance

Instance allows you to obtain instances from the IoC class. It can provide registered instances or can construct instances if the class implements Dependency.

For example getting a registered instance:

let instance = await ioc.instance(Example);

And constructing classes that implement Dependency:

class Example {
    // Can return Example or Promise<Example>
    static provide(ioc : IoC) : Example {
        return new Example();
    }
}

//...

let instance = await ioc.instance(Example);
1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago