2
votes

I have created Custom JSON based Localization Provider for IStringLocalizer and and Factory by taking an example of Askmethat-Aspnet-JsonLocalizer,

I have Also Achieved the Data Annotation Localization. and Localized the Validation Messages.

Now, Currently the requirement is that I can Update the Json based language files without restarting the application, Which is also by Injecting the IStringLocalizer as Transient Service.

But What I have observed is That Once the LocalizedStrings Loaded for the DataAnnotation, Its not updating whenever I Update the Json Its not reflecting the DataAnnotation Validation Message But It is if I use IStringLocalizer.

Is it possible that The DataAnnotation StringLocalizer is Singleton?

I have Used Below Code to Achieve DataAnnotationLocalization into startup

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

Here, Factory Implementation is injected as Transient service.

Is there Anything I missed out or Is it like the DataAnnotation Localization is Singleton Object?

1

1 Answers

0
votes

I have the exact same issue, do you find a solution for this ?

i believe you are right as mentioned

DataAnnotation Localization is Singleton Object

because even in my case if the factory create the localizer in specific culture, the same localizer will be used for future access, even if you changed the culture or the factory create new localizer (Also this could lead to Memory Leak i guess)