Created
February 14, 2022 10:36
-
-
Save steelx/246005d8b2471bd4fe41b791e5cc88ac to your computer and use it in GitHub Desktop.
Type-di demo
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 {Container, Inject, Service} from "typedi"; | |
describe('typedi demo', () => { | |
it('should work', async () => { | |
const query = () => 'hello from query'; | |
@Service() | |
class Repository { | |
constructor(@Inject('q') private q: () => string) { | |
} | |
public getHello(): string{ | |
return this.q(); | |
} | |
} | |
@Service() | |
class ExampleService { | |
constructor(private helloRepo: Repository) { | |
} | |
public getHello(): string{ | |
return this.helloRepo.getHello() | |
} | |
} | |
Container.set('q', query); | |
const service = Container.get(ExampleService) | |
expect(service.getHello()).toBe("hello from query") | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment