Auto inject
Auto dependency injector for typescript.
This is a proof of concept project, it may not be stable.
Install
$ npm install autoinject
Usage
; test = 'It works fine'; @autoInject user: User; { thisuser = user; } @autoInject db: Db; { thisdb = db; } const myClass = ; console;
All dependencies are stored on a static prototype on the target object.
;; @autoInject {} console; // [ Db ]
You can also auto instantiate a class
; test = 'It works fine'; @autoInjecte {} @autoInstantiate {} var k = ; console; // output: "It works fine"
You can always override the inject (for testing purpose)
// http.ts { // some logic }; // image-repository.ts;; @autoInjecte http: Http; { thishttp = http; } { return thishttp; }; // test.ts;; const httpMock = { return 'Nice'; };ImageRepositoryinject = httpMock; const imageRepository = ; console;
Include the typing with:
"moduleResolution": "node"
in your tsconfig.json