Skip to content

Commit 92ce766

Browse files
author
Umed Khudoiberdiev
committed
added external module usage example #65
1 parent 784d090 commit 92ce766

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {Inject, Service} from "../../src";
2+
import * as fs from "fs";
3+
4+
@Service()
5+
export class FileReader {
6+
7+
constructor(@Inject("fs") private fileSystem: typeof fs) {
8+
}
9+
10+
read(filePath: string) {
11+
return new Promise((ok, fail) => {
12+
this.fileSystem.readFile(filePath, (error, data) => {
13+
if (error) return fail(error);
14+
ok(data);
15+
});
16+
});
17+
}
18+
19+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import "reflect-metadata";
2+
import * as fs from "fs";
3+
import {Container} from "../../src";
4+
import {FileReader} from "./FileReader";
5+
6+
Container.set("fs", fs);
7+
8+
Container.get(FileReader)
9+
.read(__dirname + "/text.txt")
10+
.then(data => console.log(data.toString()));
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World!

0 commit comments

Comments
 (0)