Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
Passing arguments with Awilix

I'm using Awilix in my code for Dependecy Injection and I have this User class.

    class User {
    constructor(opts){
        this.validator = opts.validator
    }

    async validateUsername(username) {
        this.validator.username(username)
    }
    async validatePassword(password) {
            this.validator.password(password)
        }


}


    module.exports = User

Container:

const User = require('../../user/User')
const Validator = require('../../user/Validator')
const awilix = require('awilix')

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

container.register({
  user: awilix.asClass(User),
  validator: awilix.asClass(Validator),

})


module.exports = container

What I want do is to add "username" and "password" in the constructor, because those are properties of the class "User". So, it will look like this:

class User {
  constructor(opts, username, password){
      this.validator = opts.validator
      this.username = username 
      this.password = password 
  }

  async validateUsername() {
      this.validator.username(this.username)
  }
  async validatePassword() {
      this.validator.password(this.password)
      }
}


  module.exports = User

I can't figure out how to pass arguments through the constructor with Awilix.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!