New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

bmydi

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bmydi

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

latest
npmnpm
Version
1.2.5
Version published
Maintainers
1
Created
Source

一款适用于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类" 

Keywords

依赖注入,di

FAQs

Package last updated on 02 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts