Skip to content

ThatsMrTalbot/ioc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Simple typescript IoC

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published