-
Notifications
You must be signed in to change notification settings - Fork 0
/
di.ts
33 lines (28 loc) · 896 Bytes
/
di.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import "reflect-metadata";
import {container, injectable} from "tsyringe";
import { DB } from './helpers';
@injectable()
class Manager {
constructor(private db: DB){}
public GetRandomPersons(number: number) {
const persons = []
for (let i = 0; i < number; i++) {
const person = this.db.GetPersonFromDb(Math.floor(Math.random() * 9));
persons.push(person)
}
return persons
}
}
@injectable()
class PersonsController {
constructor (private manager: Manager) {}
public Get2RandomPersons() {
const value = this.manager.GetRandomPersons(2);
return value;
}
}
container.register<DB>(DB, {useClass: DB})
container.register<Manager>(Manager, {useClass: Manager})
container.register<PersonsController>(PersonsController, {useClass: PersonsController})
const controller = container.resolve(PersonsController)
console.log(controller.Get2RandomPersons());