0.0.14 • Published 2 years ago

dependency-injection-implementation v0.0.14

Weekly downloads
4
License
ISC
Repository
github
Last release
2 years ago

Dependency injection

https://www.npmjs.com/package/dependency-injection-implementation

This TypeScript library allows you to easily declare and resolve dependencies, injecting them in your classes attributes, using eye-candy TypeScript annotations.

Author: Julio Sansossio - https://github.com/Sansossio

Install

npm install dependency-injection-implementation

Example

Inject constructor

import { Injectable, InjectorApp } from 'dependency-injection-implementation'

class B {
  value = 1
}

@Injectable()
class C {
  constructor (
    readonly b: B
  ) {}
}

const app = InjectorApp.create([C, B])
const c = app.get(C)

console.log(c.b.value)
// Log: 1

Inject property

import { Injectable, Property, InjectorApp } from 'dependency-injection-implementation'

class B {
  value = 1
}

@Injectable()
class C {
  @Property()
  b: B

  @Property({ type: B })
  untyped
}

const app = InjectorApp.create([C, B])
const c = app.get(C)

console.log(c.b.value)
console.log(c.untyped.value)
// Log: 1

More examples

0.0.14

2 years ago

0.0.13

3 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago