Jecht - Simple DI
A basic dependency injection library for modern JS.
Quickstart
Install from NPM:
npm install jecht
Annotate dependencies:
; { // Get some things } @ { thisfooService = fooService; }
Get instance with injected dependencies:
var injector = ;var barService: BarService = injector;barServicefooServiceconstructor === FooService; // true
Bind an object of a class to an instance of another class:
{ return; } { return 42; } @ { thisfoo = foo; } var injector = //; var bar: Bar = injector;barfoo; // 42
Bind a string token to an instance of a class:
{ return 42; } @ { thisfoo = foo; } var injector = ; var bar: Bar = injector;barfoo; // 42
Bind to a simple value:
@ { thisfoo = foo; } var injector = ; var bar: Bar = injector;barfoo === "string literal";
Provide alternative dependencies (for mocking, etc):
@ { // Get some other things } var injector = MockFooService;var barService = injector;barServicefooServiceconstructor === MockFooService; // true
Create a factory for a dependency:
{ // Get some things } { // Get some other things } var fooServiceFactory = Factory; @ { } var useFoo = true;var injector = ;var bar = injector;barfooServicecontructor === FooService; // true
License
MIT