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

Viewed 3012

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..
This seems simple enough, I should add an @inject annotation to my first argument. 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:

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).

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.

1 Answers

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.

Related