Lightweight Dependency Injection
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
npm install --save lightweight-di
2. Import the required decorators from the package
import { Injectable } from 'lightweight-di';
const { Injectable } = require('lightweight-di');
3. Decorate classes with dependencies
@Injectable
class FileLogger {
constructor(private fs: FileSystem) { }
log(message: string) {
fs.appendToFile('app.log', message);
}
}
4. Bootstrap your application entry point with Injector
import { Injector } from 'lightweight-di';
const injector = Injector.resolveAndCreate([App, Dependency1, Dependency2]);
injector.get(App).run();
Documentation & Examples
For the full API check out the documentation
or the examples on GitHub.
License
MIT