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

How to use Service in Global-interceptor in NEST Js #731

Closed
shaharyar123 opened this issue May 25, 2018 · 2 comments
Closed

How to use Service in Global-interceptor in NEST Js #731

shaharyar123 opened this issue May 25, 2018 · 2 comments

Comments

@shaharyar123
Copy link

I want to use service in global interceptor.

My code look like this in Global-interceptor file:

import { VariablesService } from '../app/modules/variables/variables.service';

@Interceptor()
export class globalInterceptor implements NestInterceptor {
  constructor(private service: VariablesService) {
    console.log('contructor running', service);  //getting null here
  }

and on server.ts first i was initializing like this :

app.useGlobalInterceptors(new globalInterceptor())

but after the injection of service i have to do some modification because parameters are needed now in globalInterceptor()

const variableService = await app.get<VariablesService>(VariablesService);
  app.useGlobalInterceptors(new globalInterceptor(variableService));

Now what the problem is I am getting service is null .
I am unable to create the object of the service

Stack-overflow : Link

@kamilmysliwiec
Copy link
Member

@lock
Copy link

lock bot commented Sep 24, 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 24, 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

2 participants