项目作者: leonadler

项目描述 :
Lightweight dependency injection for TypeScript and JavaScript
高级语言: TypeScript
项目地址: git://github.com/leonadler/lightweight-di.git
创建时间: 2017-06-21T21:38:07Z
项目社区:https://github.com/leonadler/lightweight-di

开源协议:MIT License

下载


Lightweight Dependency Injection

npm version
travis build status

A dependency injection library for node and the browser, based on Angulars DI.
Optimized for use via TypeScript or babel decorators.

Getting started

1. Install the library in your project

  1. npm install --save lightweight-di

2. Import the required decorators from the package

  1. // TypeScript / Babel / Webpack
  2. import { Injectable } from 'lightweight-di';
  3. // Node.js / Browserify
  4. const { Injectable } = require('lightweight-di');

3. Decorate classes with dependencies

  1. @Injectable
  2. class FileLogger {
  3. constructor(private fs: FileSystem) { }
  4. log(message: string) {
  5. fs.appendToFile('app.log', message);
  6. }
  7. }

4. Bootstrap your application entry point with Injector

  1. import { Injector } from 'lightweight-di';
  2. const injector = Injector.resolveAndCreate([App, Dependency1, Dependency2]);
  3. injector.get(App).run();

Documentation & Examples

For the full API check out the documentation
or the examples on GitHub.

License

MIT