-
-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
instantiate custom rules with DI #381
Comments
Is this a shortcut for doing something like: ValidationRules.customRule(
'email-unique',
container.get(ValidateEmailUniqueness).validate
); Another thing you could do today is: main.js export function configure(aurelia: Aurelia) {
aurelia.use....
...
.feature('./custom-rules')
... custom-rules.js configure(config: FrameworkConfiguration) {
const service = config.container.get(EmailService);
ValidationRules.customRule(
'email-unique',
value => service.checkUnique(value)
);
ValidationRules.customRule(
...
...
);
} what do you think? |
I have proposed a solution for this. One would be able to use DI to instantiate Note that part of this is also to support tagged rules, using This API has the advantage going forward of making it quite easy to extend the way It is forked from another branch of mine, hence the "FluentRulesGenerator", but could easily be made to work with the current master, if FluentRulesGenerator is not also accepted as a change.
|
Apparently, there is no way to inject something from DI container when creating a custom rule. For example, I want to inject preconfigured
HttpClient
that exists in the container in order to call the backend for checking e-mail uniqueness.Currently, you need to wrap the custom rule definition in an artificial class which you need to inject only in order to register the cutom rule (see an example of such).
I wish I could define a custom rule as a class, that would be instantiated with DI, resolving all of its dependencies.
Dream:
Definition:
Registration (not sure if it is mandatory if we use class name directly):
Usage:
The text was updated successfully, but these errors were encountered: