Skip to content
/ iocoo Public

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

License

Notifications You must be signed in to change notification settings

shalldie/iocoo

Repository files navigation

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published