dependency-injection-implementation
v0.0.14
Published
Simple depency injection implementation
Downloads
22
Maintainers
Readme
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-implementationExample
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