1.2.5 • Published 4 years ago

bmydi v1.2.5

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

一款适用于Typescript项目的简易依赖注入插件

只支持类的属性进行注入,本人使用最多的也是这种方式

安装

npm i --save bmydi

使用

  • @Injectable():加在需要被注入的类上,主要作用是收集依赖
  • @Inject():放在类的属性上,会把@Injectable()的类注入到属性上

示例:

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类" 
1.2.5

4 years ago

1.2.3

4 years ago

1.2.1

4 years ago

1.0.0

4 years ago