Im trying use @Inject from typedi but it is not working while Container.get does.
im using node 18.16.0
typedi 0.10.0
it throw this error:
throw new cannot_inject_value_error_1.CannotInjectValueError(target, propertyName);
^
CannotInjectValueError: Cannot inject value into "TestController.useCase". Please make sure you setup reflect-metadata properly and you don't use interfaces without service tokens as injection value.
imported 'reflect-metadata' on server.ts
I have add on tsconfig.json
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"strictPropertyInitialization": false,
import { UseCase } from './usecase.model'
import { Service } from 'typedi'
@Service()
export class TestUseCase implements UseCase<any, any> {
async exec() {
return 'hello'
}
}
but when I try to inject inside a controller:
@JsonController()
@Service()
export class TestController {
@Inject()
private useCase: TestUseCase;
@Get('/any')
async createProducts() {
return await this.useCase.exec()
}
}