A lightweight dependency injection container for TypeScript/JavaScript for constructor injection.
Install by npm
npm install --save marv_injector
Modify your tsconfig.json
to include the following settings
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
Add a polyfill for the Reflect API (examples below use reflect-metadata). You can use:
The Reflect polyfill import should only be added once, and before DI is used:
// main.ts
import "reflect-metadata";
// Your code here...
Marv_injector performs Constructor Injection on the constructors of decorated classes.
Class decorator factory that allows the class' dependencies to be injected at runtime.
import {injector} from "marv_injector";
@injector()
class Foo {
constructor(private database: Database) {}
}
# Contributing
This project welcomes contributions and suggestions.