0.2.31 • Published 2 years ago

@newdash/inject v0.2.31

Weekly downloads
133
License
MIT
Repository
github
Last release
2 years ago

Dependency Inject Container

npm (scoped) Codecov Netlify Quality Gate Status Security Rating

Yet another dependency injection container for typescript

Quick Start

# install libs
npm i -S reflect-metadata @newdash/inject
// tsconfig.json
// remember enable decorator related flags
{
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true
  }
}
// import reflect lib firstly
import "reflect-metadata"; 
import { inject } from "@newdash/inject"

// a really simple example
it('should support deep constructor injection', async () => {

  class A {
    v: number
    constructor(@inject("v") v) {
      this.v = v;
    }
  }

  class B {
    a: InjectWrappedInstance<A>
    constructor(@inject(A) a) {
      this.a = a;
    }
  }

  const ic = InjectContainer.New();
  ic.registerInstance("v", 999); // define an instance provider in simple way
  const b = await ic.getInstance(B);
  expect(b.a.v).toBe(999);

});

CHANGELOG

LICENSE

0.2.31

2 years ago

0.2.30

2 years ago

0.2.29

3 years ago

0.2.28

3 years ago

0.2.27

4 years ago

0.2.26

4 years ago

0.2.25

4 years ago

0.2.24

4 years ago

0.2.23

4 years ago

0.2.22

4 years ago

0.2.21

4 years ago

0.2.20

4 years ago

0.2.19

4 years ago

0.2.18

4 years ago

0.2.17

4 years ago

0.2.16

4 years ago

0.2.15

4 years ago

0.2.14

4 years ago

0.2.13

4 years ago

0.2.12

4 years ago

0.2.11

4 years ago

0.2.9

4 years ago

0.2.7

4 years ago

0.2.8

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.3

4 years ago

0.2.4

4 years ago

0.2.2

4 years ago

0.0.14

4 years ago

0.0.13

4 years ago

0.0.12

4 years ago

0.0.10

4 years ago

0.0.11

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.5

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago