dependency-injection-implementation
TypeScript icon, indicating that this package has built-in type declarations

0.0.14 • Public • Published

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

Package Sidebar

Install

npm i dependency-injection-implementation

Weekly Downloads

0

Version

0.0.14

License

ISC

Unpacked Size

140 kB

Total Files

32

Last publish

Collaborators

  • sansossio