Created
March 12, 2021 04:53
-
-
Save AhnMo/6db3d5856fb5b3f27cbc73f8f725cd78 to your computer and use it in GitHub Desktop.
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 { Service } from 'typedi' | |
@Service() | |
export class ExampleInjectedService { | |
printMessage() { | |
console.log('I am alive!') | |
} | |
} |
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 'reflect-metadata' | |
import { Service } from 'typedi' | |
import { ExampleInjectedService } from './bar'; | |
import * as _ from 'lodash' | |
@Service() | |
export default class ExampleService { | |
constructor( | |
public injectedService: ExampleInjectedService | |
) {} | |
public test() { | |
console.log(this.injectedService) | |
this.injectedService.printMessage() | |
} | |
public test2(compareService: ExampleInjectedService) { | |
console.log(_.isEqual(compareService, this.injectedService)) | |
} | |
public getService() { | |
return this.injectedService | |
} | |
} |
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 ExampleService from './baz' | |
import { Container } from 'typedi' | |
const serviceInstance = Container.get(ExampleService); | |
let svc = serviceInstance.getService(); | |
const serviceInstance2 = Container.get(ExampleService); | |
serviceInstance2.test2(svc); | |
const serviceInstance3 = Container.get(ExampleService); | |
serviceInstance3.test2(svc); | |
serviceInstance.injectedService.printMessage() |
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
Show hidden characters
{ | |
"compilerOptions": { | |
"experimentalDecorators": true, | |
"emitDecoratorMetadata": true, | |
"lib": [ | |
"dom", | |
"es5", | |
"scripthost", | |
"es2015.symbol" | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment