Skip to content

Quobject/qs-di-ts

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dependency Injection for Typescript

Lightweight wrap of di.js for TypeScript.

NPM NPM

NPM version NPM downloads

Install

npm install qs-di-ts

Usage

You need to use

 "emitDecoratorMetadata": true,
 "experimentalDecorators": true,

when compiling typescript files.

car.ts

import {Inject} from 'qs-di-ts'
import {Engine} from './engine'

@Inject
export class Car {
  constructor(public engine: Engine) {}
}

engine.ts

export class Engine {

}

mockEngine.ts

import {Provide} from 'qs-di-ts'
import {Engine} from './engine'

@Provide(Engine)
export class MockEngine {

}

main.ts

import {Injector} from 'qs-di-ts'
import {Car} from './car'
import {Engine} from './engine'

var injector = new Injector();
var car: Car = injector.get(Car); //instantiate car, car.engine is magically instance of Engine! :)


import {MockEngine} from './mockEngine'
var injector2 = new Injector([MockEngine]);
var car2: Car = injector2.get(Car); //instantiate car, car.engine is instance of MockEngine! :)

License

MIT

About

Dependency injection for TypeScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%