简体   繁体   English

FluentValidation 日期格式不尊重 ASP.NET webapi 中的文化

[英]FluentValidation date formatting not respecting culture in ASP.NET webapi

I've configured at Startup.cs of my ASP.NET webapi the Culture for FluentValidation like below:我已经在我的 ASP.NET webapi 的 Startup.cs 中配置了 Culture for FluentValidation,如下所示:

ValidatorOptions.Global.LanguageManager.Culture = new CultureInfo("pt-BR");

The messages are follow the selected culture.消息遵循选定的文化。 When I'm running the tests in my local machine, the message is like expeted:当我在我的本地机器上运行测试时,消息就像是 expeted:

"'Data Aniversario' deve ser superior a '31/01/2022 00:00:00'." “'Data Aniversario' deve ser superior a '31/01/2022 00:00:00'。”

But when the same test run on CI pipeline the message do not use the same datetime format:但是当在 CI 管道上运行相同的测试时,消息不使用相同的日期时间格式:

"'Data Aniversario' deve ser superior a '01/31/2022 00:00:00'." “'Data Aniversario' 开发的服务优于 '01/31/2022 00:00:00'。”

The rule used for the field:该字段使用的规则:

RuleFor(x => x.DataAniversario).NotEmpty().GreaterThan(x => x.MenorDataPermitida);

To solve it was necessary to configure the default thread current culture in Startup.cs too:要解决这个问题,还需要在 Startup.cs 中配置默认线程当前文化:

CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("pt-BR");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM