Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Type-di demo
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