简体   繁体   English

缺少@inject 注释,这在使用扩展类的 inversify 中没有缺少

[英]Missing @inject annotation, which isn't missing in inversify with an extending class

I'm having a problem which seems a bit hard to put into a title, which is why you've gotten this beast of a title.我遇到了一个问题,似乎很难将其放入标题中,这就是为什么您获得了这个标题的野兽。

I get an error stating: Error: Missing required @inject or @multiInject annotation in: argument 0 in class SceneRepository.我收到一条错误消息: Error: Missing required @inject or @multiInject annotation in: argument 0 in class SceneRepository. . .
This seems simple enough, I should add an @inject annotation to my first argument.这看起来很简单,我应该在我的第一个参数中添加一个@inject注释。 This is my constructor though:这是我的构造函数:

export class SceneRepository extends BaseRepository<IScene> {
  constructor(@inject(SceneSchema) private sceneSchema: SceneSchema) {
    super(sceneSchema.schema);
  }
}

And for the sake of being complete, this is what my BaseRepository looks like:为了完整起见,这就是我的 BaseRepository 的样子:

export class BaseRepository<T extends Document> implements IWrite<T>, IRead<T>{
  constructor(private _model: Model<Document>) {

  }
  ...
}

Model<Document> Comes from a third party library (mongoose). Model<Document>来自第三方库 (mongoose)。

I have no clue to what I'm doing wrong here, so if you could nudge me in the correct direction, it would be greatly appreciated.我不知道我在这里做错了什么,所以如果你能把我推向正确的方向,我将不胜感激。

I encountered a similar issue and in my case, instead of constructor injection, I used property injection to get away with this error and also got the injection working.我遇到了类似的问题,在我的情况下,我没有使用构造函数注入,而是使用属性注入来解决此错误,并使注入正常工作。

export class SceneRepository extends BaseRepository<IScene> {
    @inject(SceneSchema)
    private sceneSchema: SceneSchema;
    constructor() {
        super(this.sceneSchema.schema);
      }
    }

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM