-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REQUEST object from core, used for Scope Request Providers is not available #1955
Comments
Is here
instead of? |
I tried using the same in my Validator Constraint but it didn't work. I wish there was a way to pass Request Params to the Validator as Constraints. I am unable to find one... had to use a work around 😞 |
@ackuser It is there: Are you sure that your |
I am unable to get this to work. Is this the correct way? This is @ValidatorConstraint({ name: 'userEmailAlreadyExist', async: true })
@Injectable({ scope: Scope.REQUEST })
export class UserEmailAlreadyExists implements ValidatorConstraintInterface {
constructor(
private readonly userRepository: UsersRepository,
@Inject(REQUEST) private readonly request: Request,
) {}
async validate(email: string, args: ValidationArguments): Promise<boolean> {
console.log(this.userRepository); // undefined
console.log(this.request); // undefined
}
} This is @Module({
imports: [
MongooseModule.forFeature([...]),
forwardRef(() => AuthModule),
],
controllers: [UsersController],
providers: [UsersRepository, UsersService, UserEmailAlreadyExists],
exports: [UsersRepository, UsersService],
}) In "dependencies": {
"@nestjs/common": "^6.0.0",
"@nestjs/core": "^6.0.0",
"@nestjs/jwt": "^6.0.0",
"@nestjs/mongoose": "^6.0.0",
"@nestjs/passport": "^6.0.0",
"@nestjs/platform-express": "^6.0.0",
"@nestjs/typeorm": "^6.0.0",
"class-transformer": "^0.2.0",
"class-validator": "^0.9.1",
} |
You cannot use request scoped providers with 3rd-party libraries (like class-validator). This is a framework feature exclusively. |
@kamilmysliwiec Could you please explain why it is not possible? Even based on the solution here #528 ? |
Because it's a framework feature :) 3rd-party libraries may use different DI systems that have nothing to do with Nest DI (e.g. class-validator). We can work around it for simple use-cases, not for more sophisticated ones (as request-scoped providers) unfortunately. |
@vkartaviy I thought of a workaround for cases where you need specific stuff from the request inside your validation components, see my comment on this issue: #528 (comment) |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I'm submitting a...
Current behavior
I am trying to implement a functionality with some request providers, I am following this example in the doc https://docs.nestjs.com/fundamentals/injection-scopes#request-provider
However, I cannot import the REQUEST object. It seems like it does not exist in the core of library
Expected behavior
The REQUEST object should be imported correctly
Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
Environment
The text was updated successfully, but these errors were encountered: