1

I'm having troubles with Awilix library. I am following the example in the documentation, but when I execute the function, it crash with this message: "AwilixResolutionError: Could not resolve 'run'".

My code is like this:

I have a file with the dependency injection in awilix:

const container = awilix.createContainer({
   injectionMode: awilix.InjectionMode.PROXY,
});
container.register({
   userRepo: awilix.asClass(UserMock),
   getUserById: awilix.asClass(GetUserByIdInteractor),     
   signin: awilix.asClass(Signin),
});
export const signin: Signin = container.resolve('signin');

The class "Signin":

export class new Signin extends UseCase { 
   constructor(private getUserById: GetUserById){ super() }

  async run(username: string, password: string) {
      // some code
  }
} 

The GetUserById class:

export class new GetUserById { 
   constructor(private userRepo: UserRepository){ super() }

  async run(id: string) {
      // some code
  }
}

The UserRepository:

export interface UserRepository { getById(id: string): Promise<User> }

The Repository implementation:

export UserMock implements UserRepository {
    getById(id: string){  
      //some code  
    }
}

Finally I use the signin constant exported in a GQL Resolver:

export class SigninResolver {
   async signin(@Arg('data', () => SigninInput){
       const res = signin(data.username, data.password);
       return res;
   }
}

Please, helpme u.u

  • Your class definition seems wrong: `export class new GetUserById`. Omit the `new` here. I guess that's just a typo, not sure if it solves your issue. – ysfaran Oct 09 '22 at 00:42
  • Yes, it's only a typo error – Jhonatan Malara Oct 11 '22 at 20:42
  • 1
    I have solved my problem changing the injectionMode to "CLASIC". I had reading the doc and find that when u create classes with a constructor like I had developed, is necesary use the "CLASIC" injection mode (by default it's in "PROXY"). – Jhonatan Malara Oct 11 '22 at 20:45

1 Answers1

0

I can confirm that

const container = createContainer({
  injectionMode: InjectionMode.CLASSIC
})

works while

const container = createContainer({
  injectionMode: InjectionMode.PROXY
})

leads to this error.

There was idea to make Classic default in awilix but was rejected https://github.com/jeffijoe/awilix/issues/68

Daniel
  • 7,684
  • 7
  • 52
  • 76