Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Created March 21, 2017 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinyoo/6e3b18bbb76ab2f390986e8d837aa55e to your computer and use it in GitHub Desktop.
Save justinyoo/6e3b18bbb76ab2f390986e8d837aa55e to your computer and use it in GitHub Desktop.
Using IoC Container in Vue.js and TypeScript App
// models/Warrior.ts
import { inject, injectable } from "inversify";
import SERVICE_IDENTIFIER from "./Identifiers";
import Warrior from "../interfaces/Warrior";
import Weapon from "../interfaces/Weapon";
@injectable()
class Ninja implements Warrior {
public constructor(
@inject(SERVICE_IDENTIFIER.WEAPON) weapon: Weapon
) {
this.name = "Ninja";
this.weapon = weapon;
}
public name: string;
public weapon: Weapon;
}
@injectable()
class Samurai implements Warrior {
public constructor(
@inject(SERVICE_IDENTIFIER.WEAPON) weapon: Weapon
) {
this.name = "Samurai";
this.weapon = weapon;
}
public name: string;
public weapon: Weapon;
}
export { Ninja, Samurai };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment