first commit

This commit is contained in:
编码猿
2024-09-27 01:24:57 +08:00
commit b6fac0aad8
16 changed files with 252 additions and 0 deletions

38
README.md Normal file
View File

@@ -0,0 +1,38 @@
> 一款适用于Typescript项目的简易依赖注入插件
**只支持类的属性进行注入,本人使用最多的也是这种方式**
## 安装
```bash
npm i --save bmydi
```
## 使用
- @Injectable():加在需要被注入的类上,主要作用是收集依赖
- @Inject():放在类的属性上,会把`@Injectable()`的类注入到属性上
示例:
```typescript
import { Inject, Injectable } from "bmydi";
@Injectable()
class Demo1 {
public hello: string = "我是Demo1类"
}
class Demo2 {
@Inject()
public test!: Demo1;
public GetTest(): string {
return this.test.hello
}
}
var a = new Demo2();
console.log(a.GetTest()); // 返回:"我是Demo1类"
```