@thatsmrtalbot/ioc
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

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);

Readme

Keywords

none

Package Sidebar

Install

npm i @thatsmrtalbot/ioc

Weekly Downloads

0

Version

1.0.8

License

MIT

Last publish

Collaborators

  • thatsmrtalbot