File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed
sample/sample14-external-imports Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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 ( ) ) ) ;
Original file line number Diff line number Diff line change 1+ Hello World!
You can’t perform that action at this time.
0 commit comments