A dependency injection library for node and the browser, based on Angulars DI. Optimized for use via TypeScript or babel decorators.
npm install --save lightweight-di
// TypeScript / Babel / Webpack
import { Injectable } from 'lightweight-di';
// Node.js / Browserify
const { Injectable } = require('lightweight-di');
@Injectable
class FileLogger {
constructor(private fs: FileSystem) { }
log(message: string) {
fs.appendToFile('app.log', message);
}
}
import { Injector } from 'lightweight-di';
const injector = Injector.resolveAndCreate([App, Dependency1, Dependency2]);
injector.get(App).run();
For the full API check out the documentation or the examples on GitHub.