gpt4 book ai didi

asp.net-core - 自定义 DataAnnotations 本地化 - 仅创建单例对象

转载 作者:行者123 更新时间:2023-12-05 07:24:46 26 4
gpt4 key购买 nike

我以 Askmethat-Aspnet-JsonLocalizer 为例,为 IStringLocalizer 和 Factory 创建了基于自定义 JSON 的本地化提供程序。 ,

我也实现了数据标注本地化。并将验证消息本地化。

现在,目前的要求是我可以在不重新启动应用程序的情况下更新基于 Json 的语言文件,这也是通过将 IStringLocalizer 作为 transient 服务注入(inject)。

但我观察到的是,一旦为 DataAnnotation 加载了 LocalizedStrings,每当我更新 Json 时它都不会更新,它不会反射(reflect) DataAnnotation 验证消息,但如果我使用 IStringLocalizer,它就会更新。

DataAnnotation StringLocalizer 有没有可能是单例的?

我已经使用下面的代码在启动时实现了 DataAnnotationLocalization

services.AddMvcCore()
.AddDataAnnotations()
.AddDataAnnotationsLocalization(options =>
{
options.DataAnnotationLocalizerProvider = (type, factory) =>
factory.Create(string.Empty, string.Empty);
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

在这里,Factory Implementation 被注入(inject)为 Transient 服务。

有没有我遗漏的东西,或者 DataAnnotation Localization 是 Singleton Object 吗?

最佳答案

我有完全相同的问题,你找到解决方案了吗?

我相信你说的是对的

DataAnnotation Localization is Singleton Object

因为即使在我的情况下,如果工厂在特定文化中创建本地化程序,相同的本地化程序将用于 future 访问,即使您更改了文化或工厂创建了新的本地化程序(我猜这也可能导致内存泄漏)

关于asp.net-core - 自定义 DataAnnotations 本地化 - 仅创建单例对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55182595/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com