iocoo
v0.0.3
Published
IOC library in OOP. 为 OOP 设计的 IOC 库。
Downloads
3
Readme
iocoo
IOC library in OOP. 为 OOP 设计的 IOC 库。
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