Created
February 19, 2019 14:13
-
-
Save mreis1/a4586d8cf8a8fd87d8a1076234d8558d to your computer and use it in GitHub Desktop.
Node Decorators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
Injectable, | |
Inject, | |
Container, | |
InjectionToken | |
} from '@decorators/di'; | |
import {FBGenericParser} from 'htz-firebird'; | |
const API_URL = new InjectionToken('API_URL'); | |
const MY_FACTORY = new InjectionToken('MY_FACTORY'); | |
@Injectable() | |
export class MyFactory { | |
constructor( | |
@Inject(API_URL) private apiUrl: string, | |
) { | |
} | |
test() { | |
console.log({ | |
value: this, | |
url: this.apiUrl | |
}) | |
} | |
} | |
@Injectable() | |
export class HttpService { | |
constructor( | |
@Inject(API_URL) private apiUrl: string, | |
@Inject(MY_FACTORY) private factory: MyFactory | |
) { | |
} | |
public send(options: object): Promise<any> { | |
console.log(this.factory); | |
return Promise.resolve('test')//fetch(this.apiUrl, options); | |
} | |
} | |
Container.provide([ | |
{provide: API_URL, useValue: 'http://server.localhost'}, | |
{provide: MY_FACTORY, useValue: new MyFactory('TEST')} | |
]); | |
const httpService = Container.get<HttpService>(HttpService); | |
httpService.send({}); | |
console.log(httpService); | |
export * from './sale'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ ts-node ./src/index.ts
MyFactory { apiUrl: 'TEST' }
HttpService {
apiUrl: 'http://server.localhost',
factory: MyFactory { apiUrl: 'TEST' } }