Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

di-decorator

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

di-decorator

Dependency Injection library for TypeScript

latest
Source
npmnpm
Version
1.0.4
Version published
Maintainers
1
Created
Source

Build Status Downloads

Simple DI in class method in TS

Dependency injection library for TypeScript

How to use?

$ npm i di-decorator
# OR
$ yarn add di-decorator

TypeScript


import { diInject } from 'di-decorator';

const oneToken = 'tokenOne';
const secondToken = 'secondToken';

class Test {
  injectToken: string;
  sr: string;
  constructor(sr: string) {
    this.sr = sr;
  }

  @diInject({
    injectToken: oneToken,
  })
  callFirstToken() {
    console.group('First');
    console.log(this.injectToken);
    console.groupEnd();
  }

  @diInject({
    injectToken: secondToken,
  })
  callSecondToken(a) {
    console.group('Second');
    console.log(this.injectToken);
    this.callFirstToken();
    console.groupEnd();
  }

  @diInject({
    sr: 'changedSR',
  })
  callThirdOne() {
    console.group('Third');
    this.callFirstToken();
    this.callSecondToken(5);
    console.log('this.sr=', this.sr);
    console.groupEnd();
  }

  getOriginal() {
    console.log(this.sr);
  }
}

const t = new Test('originalSR');
t.callFirstToken();
/*
First
  this.injectToken=tokenOne
*/
t.callSecondToken(5);
/*
Second
  this.injectToken=secondToken
  First
    this.injectToken=tokenOne
  this.injectToken=secondToken
*/
t.callThirdOne();
/*
Third
  First
    this.injectToken=tokenOne
  Second
    this.injectToken=secondToken
    First
      this.injectToken=tokenOne
    this.injectToken=secondToken
  this.sr=changedSR   
*/
t.getOriginal();
// originalSR


Use cases

  • Easy testing method class without any hard injections.
  • Create simple DI in typescript project.

Keywords

DI

FAQs

Package last updated on 10 Jan 2019

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