Dependency injection
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)
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)
More examples