1

I use the awilix library for achieving DI in my nodejs express project which used ES6 and nodejs 12.x.

Let's say I have a base class and a subclass as follows

class MyBaseClass {
    #collectionName;

    constructor(collectionName) {
        this.#collectionName = collectionName;
    }

    getCollection() {
        return this.#collection;
    }
}

class MySubClass extends MyBaseClass {
    constructor() {
        super("users");
    }
}

I use awilix.InjectionMode.CLASSIC. When I try to resolve and instance of MySubClass, I get a resolution error which basically says "Could not resolve 'collectionName'". MySubClass does not need constructor parameters to be passed in order to be instantiated. What am I doing wrong?

Harindaka
  • 4,658
  • 8
  • 43
  • 62

0 Answers0