3

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.

Pjetr
  • 1,372
  • 10
  • 20
  • 1
    Did you find a solution? – andrew Jun 22 '17 at 07:25
  • Hi @andrew, no I haven't, **and** yes I have. I did some rewriting and wrote around the error. You'll forgive me for not remembering the specifics? But IIRC i simply created a getter and a setter for the `_model`, and no longer set it using `super()`. Because I believe it had to do with having required completely different parameters to the constructor. So I did not really fix the issue, I removed it :D – Pjetr Jun 23 '17 at 06:25

1 Answers1

0

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.

  • 1
    `'TypescriptInterface' only refers to a type, but is being used as a value here` I got this error if I add `@inject(TypescriptInterface)` – Alan Yong Oct 20 '21 at 05:11