Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shalldie/iocoo
IOC library in OOP. 为 OOP 设计的 IOC 库。
https://github.com/shalldie/iocoo
di ioc oop
Last synced: about 1 month 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 (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-03-25T08:39:05.000Z (over 2 years ago)
- Last Synced: 2024-10-13T01:34:34.744Z (2 months 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]
[![test status](https://img.shields.io/github/workflow/status/shalldie/iocoo/ci?label=test&logo=github&style=flat-square)](https://github.com/shalldie/iocoo/actions)
[![license](https://img.shields.io/npm/l/iocoo?logo=github&style=flat-square)](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