Are there any examples around using this ico with ES6 rather than Typescript for back-end Node/Express ? I followed a few Typescript examples but nothing for ES6. I've looked at the generated ES5 from Typescript but this seems a backwards step
Asked
Active
Viewed 1,028 times
1 Answers
2
The documentation covers this (also can be seen here):
var inversify = require("inversify");
require("reflect-metadata");
var TYPES = {
Ninja: "Ninja",
Katana: "Katana",
Shuriken: "Shuriken"
};
class Katana {
hit() {
return "cut!";
}
}
class Shuriken {
throw() {
return "hit!";
}
}
class Ninja {
constructor(katana, shuriken) {
this._katana = katana;
this._shuriken = shuriken;
}
fight() { return this._katana.hit(); };
sneak() { return this._shuriken.throw(); };
}
// Declare as injectable and its dependencies
inversify.decorate(inversify.injectable(), Katana);
inversify.decorate(inversify.injectable(), Shuriken);
inversify.decorate(inversify.injectable(), Ninja);
inversify.decorate(inversify.inject(TYPES.Katana), Ninja, 0);
inversify.decorate(inversify.inject(TYPES.Shuriken), Ninja, 1);
// Declare bindings
var container = new inversify.Container();
container.bind(TYPES.Ninja).to(Ninja);
container.bind(TYPES.Katana).to(Katana);
container.bind(TYPES.Shuriken).to(Shuriken);
// Resolve dependencies
var ninja = container.get(TYPES.Ninja);
return ninja;

Estus Flask
- 206,104
- 70
- 425
- 565
-
Yes, they don't have wiki where you expect to see it (in GH's Wiki section). Btw, if you're interested in Angular-like DI, it is [reasonably usable with Node](http://stackoverflow.com/a/38923612/3731501). It was recently extracted from `@angular/core` (which contains some non-DI junk) into a [separate package](https://github.com/mgechev/injection-js) by a member of Angular team. – Estus Flask Jan 26 '17 at 08:54