0.0.31 • Published 8 years ago

di-ts v0.0.31

Weekly downloads
3
License
ISC
Repository
github
Last release
8 years ago

Dependency Injection for Typescript

Lightweight wrap and extension of di.js for TypeScript.

Install

npm install di-ts

Usage

You need to use --emitDecoratorMetadata flag when compile you typescript files. "emitDecoratorMetadata" flag is supported by the 1.5 beta version of TypeScript.

car.ts

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

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

engine.ts

export class Engine {

}

mockEngine.ts

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

@Provide(Engine)
export class MockEngine {

}

main.ts

/// <reference path="node_modules/di-ts/di-ts.d.ts"/>

import {Injector} from '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! :)
0.0.31

8 years ago

0.0.30

9 years ago

0.0.29

9 years ago

0.0.28

9 years ago

0.0.26

9 years ago

0.0.18

9 years ago

0.0.17

9 years ago

0.0.16

9 years ago

0.0.15

9 years ago

0.0.14

9 years ago

0.0.13

9 years ago

0.0.12

9 years ago

0.0.11

9 years ago

0.0.10

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago