Q:

Nestjs, met some problems when using dependency injected class's method in interceptors, inject can't be resolved

I injected a provider(FileFilter) in my controller, and I want to use its filter method in Interceptors. 
@Controller('file-uploader')
export class FileUploaderController {

    constructor(private fileFilter: FileFilter) {}

    @Post()
    @UseInterceptors(
        FileInterceptor('file', {
            fileFilter: this.fileFilter.filter,
        }))

    uploadFile(@UploadedFile() file) {
        return file;
    }
}

here is FileFilter

@Injectable()
export class FileFilter {
    filter(req: any, file: MulterFile, callback: any) {
        if (! file.mimetype.match(ASSESSMENT_FILE_TYPE)) {
            return callback(new HttpException(null, HttpStatus. BAD_REQUEST), false);
        }
        return callback(null, true);
    }

}

when I use postman to request the API, the error message is like the following:
fileFilter: this.fileFilter.filter,
[0]                          ^
[0] TypeError: Cannot read property 'filter' of undefined

BUT inside the post method, the filter can be used which means the FileFilter is injected correctly, then who can explain why this doesn't work in an interceptor?  or is this about the init order or something?  Help, please. 

A:

Decorators have a different Lexical this which does not belong to the class, so this.fileFilter.filter is undefined as this does not have a property called fileFilter.  I believe you would need to save the filter method as a function and not part of a class to use it like that

