IoC in Aurelia with parameteraized constructor

Hello everybody

I wrote a library for a metering password as password-meter

I should use it like the following


let passwordMeter= new PasswordMeter({
    minLength: 5,
    maxLength: 10,
    uppercaseLettersMinLength: 1,
    lowercaseLettersMinLength: 2,
    numbersMinLength: 1,
    symbolsMinLength: 1,
    include: ['a', '$'],
    exclude: ['1baA$', '0xaZ$'],
    startsWith: '1',
    endsWith: '$',
    blackList : ['123456','p@ssw0rd']
}, {
        "40": "veryWeak",    // 001 <= x <  040
        "80": "weak",        // 040 <= x <  080
        "120": "medium",     // 080 <= x <  120
        "180": "strong",     // 120 <= x <  180
        "200": "veryStrong", // 180 <= x <  200
        "_": "perfect"       //        x >= 200
    }

let result = passwordMeter.getResult('1pwQvF@87$');

As you see, The constructor is not parameterless and you should pass two objects to the constructor

  1. Configs
  2. Ranges

How can I do this with Aurelia IoC (inject PasswordMeter to other classes)?
Does Aurelia DI just work with parameterless classes?

You have to inject a to be generated PasswordMeterFactory class instead. Inside, you can connect the configs and ranges to the PasswordMeter class.

1 Like

so in summery, We must use a class with parameter-less constructor for injection Am I right?

AFAIK, yes. You always inject a complete class instance, so fully configured.

1 Like

Actually, it seems there are a couple of options on how to handle your case. See the examples in the next StackOverflow article.


Never too old to learn something :wink:

1 Like