Skip to content
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

Allow localization in ICustomValidate context #2899

Closed
reberinformatik opened this issue Jan 16, 2018 · 3 comments
Closed

Allow localization in ICustomValidate context #2899

reberinformatik opened this issue Jan 16, 2018 · 3 comments
Milestone

Comments

@reberinformatik
Copy link
Contributor

Domain objects or dtos can implement ICustomValidate to implement complex validation logic. See documentation.

The CustomValidatationContext provides no easy way to translate validation-messages. Localized validation messages are crucial for a good user-experience.

One could resolve ILocalizationManager as a workaround, as CustomValidatationContext exposes an IocResolver.
But this adds an implicit dependency on ILocalizationManager (Service Locator antipattern). Probably an interception of the validation chain could be the solution to this. In the Dto I would only provide the key (and probably additional parameters) to the localized text. This could be done by inheriting from ValidationResult.

An other (easier) way would be to expose a localization method directly in the CustomValidatationContext.

@ismcagdas ismcagdas added this to the v3.5 milestone Jan 16, 2018
@KennyEng12
Copy link

Hi,

May I know is this being implemented? Because I'm trying to use Localization in DTO level.

Thanks.

@hikalkan
Copy link
Member

@reberinformatik:

An other (easier) way would be to expose a localization method directly in the CustomValidatationContext.

You can just create an extension method for that (this method resolves the ILocalizationManager and localizes the given string).

If you want to send a PR, it's accepted.

@hikalkan
Copy link
Member

Extend to ILocalizationManager and inject to DTO?

No. Just a static extension method for CustomValidatationContext class.

ismcagdas added a commit that referenced this issue Feb 28, 2018
hikalkan added a commit that referenced this issue Feb 28, 2018
resolves #2899 Added localize extension method for CustomValidationContext
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants