[BUG] [typescript-nestjs-server] Cannot use Injectables in ApiImplementations
Description
If I want to implement a functionality in an ApiInterface i cannot inject services from the AppModule because they are not known to the ApiModule which is creating all those instances.
openapi-generator version
7.15
Steps to reproduce
Take the PetStore-Demo and add a TestService which is called from the UserService in the constructor:
@Injectable() export class TestService { hello(): string { return "Hello World"; } }
`@Injectable() export class UserService implements UserApi {
constructor(private readonly testService: TestService) {}`
If you do that, you'll receive an error in the startup:
Nest can't resolve dependencies of the UserService (?). Please make sure that the argument TestService at index [0] is available in the ApiModule context
There are 3 possible solutions for fixing this problem:
- @Global on the module where the service are that you want to use
- Add in the Module-Template of your integration the import of the needed module
- Use the moduleRef in the constructor and bind the service in the onModuleInit-Phase:
constructor(private readonly moduleRef: ModuleRef) {}
onModuleInit(): any {
this.testService = this.moduleRef.get(TestService, {strict: false});
}
I used the moduleRef.
cc @aryobenholzner
Thanks for the ping, I will look into this