Undefined services on scope transient
I have an issue when using scope transient.
It prevents the injected services from being injected at all and therefore all dependencies are undefined.
I am aware of a similar issue, but the issue here is with scope transient, which unlike scope request, should not be related to http requests.
Bare-bones example:
import { Injectable, Scope } from '@nestjs/common';
import { HttpService } from '@nestjs/axios';
import { TestService } from '../test-service/test.service'
@Injectable({ scope: Scope.TRANSIENT })
export class MyService {
constructor(
private readonly httpService: HttpService,
private readonly testServie: TestService,
) {}
@RabbitSubscribe({
exchange: 'TEST',
routingKey: 'TEST',
queue: 'TEST_TEST',
})
async main({ msg: any }: { msg: any }) {
console.log(this.httpService); // undefined
console.log(this.testServie); // undefined
console.log(msg); // msg received properly
return msg
}
}
If no scope is given (meaning default scope is used), then everything works. This line
@Injectable({ scope: Scope.TRANSIENT })
changed to this
@Injectable()
However, it is necessary to use scope transient for this project. any suggestions for a solution?
Using nestjs 8.
@dany-nrich We're not sure that nestjs 8 works correctly yet with our current version, that's my primary goal soon to make sure we do support it because there are really good changes Can you give us a repro? Also could you try using the same nestjs version we're using at this moment just to make sure it's not something new?
@dany-nrich I'm reaching you to know if you have found a way around this or if Nestjs v8 helped you achieve what you're trying to? I'm closing this issue but you can re-open if its still happening and if you can provide us a repro
I am facing the exact same issue right now
import { Injectable, Scope } from '@nestjs/common';
import { HttpService } from '@nestjs/axios';
import { TestService } from '../test-service/test.service'
@Injectable()
export class MyService {
constructor(
private readonly httpService: HttpService,
private readonly testServie: TestService,
) {}
@RabbitSubscribe({
exchange: 'TEST',
routingKey: 'TEST',
queue: 'TEST_TEST',
})
async main({ msg: any }: { msg: any }) {
console.log(this.httpService); // undefined
console.log(this.testServie); // undefined
console.log(msg); // msg received properly
return msg
}
}
I am also having this issue the services that I am injecting are undefined
am not even giving any scope just
@Injectable()