0.0.3 • Published 2 years ago

iocoo v0.0.3

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

iocoo

IOC library in OOP. 为 OOP 设计的 IOC 库。

npm test status license

Installation

reflect-metadata is required.

npm install iocoo reflect-metadata --save

Usage & Example

import 'reflect-metadata';
import { Inject, Injectable, getInstance } from 'iocoo';

@Injectable({ singleton: true })
class Child {
    @Inject()
    public child!: Child;
}

@Injectable({ singleton: false })
class Child2 {
    @Inject()
    public child2!: Child2;
}

@Injectable()
class Person {
    @Inject()
    public child!: Child;

    @Inject()
    public child2!: Child2;
}

// getInstance may return the instance of a class
const p = getInstance(Person);

// child is singleton
expect(p.child).toBe(p.child.child);

// child2 is not
expect(p.child2).not.toBe(p.child2.child2);

License

MIT