Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

di-ts

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

di-ts

Lightweight wrap and extension of angular/di.js for TypeScript.

  • 0.0.28
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-83.33%
Maintainers
1
Weekly downloads
 
Created
Source

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! :)

Keywords

FAQs

Package last updated on 06 May 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc