注入类的构造器
绑定一个抽象到类的构造器。
@injectable()
class Ninja implements Ninja {
private _katana: Katana;
private _shuriken: Shuriken;
public constructor(
@inject("Newable<Katana>") Katana: Newable<Katana>,
@inject("Shuriken") shuriken: Shuriken
) {
this._katana = new Katana();
this._shuriken = shuriken;
}
public fight() { return this._katana.hit(); };
public sneak() { return this._shuriken.throw(); };
}
container.bind<interfaces.Newable<Katana>>("Newable<Katana>").toConstructor<Katana>(Katana);