Skip to content
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

Injection scopes: Scope.REQUEST doesn't work on @nestjs/microservices #1886

Closed
ghost opened this issue Mar 30, 2019 · 2 comments
Closed

Injection scopes: Scope.REQUEST doesn't work on @nestjs/microservices #1886

ghost opened this issue Mar 30, 2019 · 2 comments

Comments

@ghost
Copy link

ghost commented Mar 30, 2019

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

I'm using Injection scope REQUEST for Microservices (tested all Transports)


import { Controller, Scope } from '@nestjs/common';
import { AppService } from './app.service';
import { MessagePattern } from '@nestjs/microservices';

@Controller({ scope: Scope.REQUEST })
export class AppController {
  constructor(private readonly appService: AppService) {
    console.log('AppController created');
  }

  @MessagePattern({ cmd: 'ahihi' })
  getHello(ahihi: string): string {
    console.log('Received message ???');
    return this.appService.getHello();
  }
}

  • Got errors:


(node:28609) UnhandledPromiseRejectionWarning: TypeError
    at Object.getMetadata (/Users/khoahoang/Desktop/a/node_modules/reflect-metadata/Reflect.js:354:23)
    at ExceptionFiltersContext.reflectMethodMetadata (/Users/khoahoang/Desktop/a/node_modules/@nestjs/core/helpers/context-creator.js:20:24)
    at ExceptionFiltersContext.createContext (/Users/khoahoang/Desktop/a/node_modules/@nestjs/core/helpers/context-creator.js:8:37)
    at ExceptionFiltersContext.create (/Users/khoahoang/Desktop/a/node_modules/@nestjs/microservices/context/exception-filters-context.js:15:30)
    at RpcContextCreator.create (/Users/khoahoang/Desktop/a/node_modules/@nestjs/microservices/context/rpc-context-creator.js:18:63)
    at server.addHandler.data (/Users/khoahoang/Desktop/a/node_modules/@nestjs/microservices/listeners-controller.js:29:51)
    at ServerTCP.handleMessage (/Users/khoahoang/Desktop/a/node_modules/@nestjs/microservices/server/server-tcp.js:46:60)
    at Socket.readSocket.on (/Users/khoahoang/Desktop/a/node_modules/@nestjs/microservices/server/server-tcp.js:27:70)
    at Socket.emit (events.js:182:13)
    at Socket.EventEmitter.emit (domain.js:441:20)
(node:28609) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:28609) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

  • Currently, I working around for this issue by add (contextId,
    inquirerId) into :
    • packages/microservices/listeners-controller.ts
    • packages/microservices/context/rpc-context-creator.ts
    • packages/microservices/context/exception-filters-context.ts
      and added Request context for microservices
      master...hovonako:hovonako

Minimal reproduction of the problem with instructions

https://github.com/hovonako/nestjs-issue

What is the motivation / use case for changing the behavior?

Environment


Nest version: 6.0.4

 
For Tooling issues:
- Node version: 11  
- Platform: Mac 

Others:

@ghost ghost changed the title InjectableScope.REQUEST Injection scopes: Scope.REQUEST doesn't work on @nestjs/microservices Mar 30, 2019
@kamilmysliwiec
Copy link
Member

Fixed in 6.0.5 :) Thanks for reporting

@lock
Copy link

lock bot commented Sep 23, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant