Register Transient and AutoInject

Hi.

I have a custom validation controller and in order for it to work with “& validate” I need to inject it like this:

@inject(NewInstance.of(CustomValidationController).as(ValidationController))

and this works fine.

Topic here why this is needed: https://github.com/aurelia/validation/issues/469

However I am now trying to do this with autoinject. I added:

aurelia.use.transient(CustomValidationController, () => NewInstance.of(CustomValidationController).as(ValidationController));

in my main.js file but it’s not working.

I also tried to use “.key” and “.asKey” but same result. I get the “A ValidationController has not been registered.” error.

Any ideas?

Thanks.

Honestly, I don’t know what NewInstance.as does, but try using container:

aurelia.container.registerTransient( CustomValidationController );

And probably this will be exactly what you want:

aurelia.container.registerTransient( ValidationController, CustomValidationController );

Now when you try to autoinject ValidationController, you get a new instance of CustomValidationController.