https://github.com/shalldie/iocoo
IOC library in OOP. 为 OOP 设计的 IOC 库。
https://github.com/shalldie/iocoo
di ioc oop
Last synced: 8 months ago
JSON representation
IOC library in OOP. 为 OOP 设计的 IOC 库。
- Host: GitHub
- URL: https://github.com/shalldie/iocoo
- Owner: shalldie
- License: mit
- Created: 2017-05-10T18:34:13.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2022-03-25T08:39:05.000Z (about 4 years ago)
- Last Synced: 2025-02-18T11:06:08.265Z (over 1 year ago)
- Topics: di, ioc, oop
- Language: TypeScript
- Homepage:
- Size: 432 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# iocoo
IOC library in OOP. 为 OOP 设计的 IOC 库。
[![npm][iocoo-icon]][iocoo-npm]
[](https://github.com/shalldie/iocoo/actions)
[](https://github.com/shalldie/iocoo)
## Installation
[reflect-metadata](https://www.npmjs.com/package/reflect-metadata) is required.
npm install iocoo reflect-metadata --save
## Usage & Example
```ts
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
[iocoo-icon]: https://img.shields.io/npm/v/iocoo.svg?logo=npm&style=flat-square
[iocoo-npm]: https://www.npmjs.com/package/iocoo