Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: Localizing with external service

$
0
0

Hi Jeremy,

I have the folowing validator, (the real validator in my project have 20 fields and property validation for each one):

 

publicclass ContactValidator : AbstractValidator<Contact>
{
        [Inject] IMessageProvider Provider { privateget; set; }
		
	public ContactValidator()
        {
            RuleFor(x => x.Email)
            .Must(x => x.Length <= 100).WithMessage(Provider.GetText("Validation_EmailTooLong"))
            .EmailAddress().WithMessage(Provider.GetText("Validation_InvalidEmail"));
        }
}

 

The problem there is when the validator is created, there are several calls to Provider.GetText(...). The better way would be call Provider.GetText(...) on demand.

In your last post you says the solution is using  IStringSource and manually setting the ErrorMessageSource.

Please can you explain me how that can fit in my code above.

Thanks

Cristhiam


Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>