0.0.14 • Published 1 year ago

dependency-injection-implementation v0.0.14

Weekly downloads
4
License
ISC
Repository
github
Last release
1 year 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

1 year ago

0.0.13

3 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago