Skip to content

Commit

Permalink
Optimization& refactor: Move localizer inside the validation control
Browse files Browse the repository at this point in the history
  • Loading branch information
hikalkan committed Dec 28, 2019
1 parent d153a6b commit c010c56
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,20 @@ public class LimitedResultRequestDto : ILimitedResultRequest, IValidatableObject

public virtual IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
var l = validationContext.GetService(typeof(IStringLocalizer<AbpDddResource>)) as IStringLocalizer<AbpDddResource>;

if (MaxResultCount > MaxMaxResultCount)
{
var localizer = (IStringLocalizer<AbpDddResource>)validationContext
.GetService(typeof(IStringLocalizer<AbpDddResource>));

yield return new ValidationResult(
errorMessage:l?["MaxResultCountExceededExceptionMessage", nameof(MaxResultCount), MaxMaxResultCount, typeof(LimitedResultRequestDto).FullName, nameof(MaxMaxResultCount)],
new []{nameof(MaxResultCount)});
localizer[
"MaxResultCountExceededExceptionMessage",
nameof(MaxResultCount),
MaxMaxResultCount,
typeof(LimitedResultRequestDto).FullName,
nameof(MaxMaxResultCount)
],
new[] { nameof(MaxResultCount) });
}
}
}
Expand Down

0 comments on commit c010c56

Please sign in to comment.