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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.8
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.8
    1
  • 1.0.7
    2
  • 1.0.6
    0
  • 1.0.5
    0

Package Sidebar

Install

npm i @thatsmrtalbot/ioc

Weekly Downloads

1

Version

1.0.8

License

MIT

Last publish

Collaborators

  • thatsmrtalbot