C
C#2y ago
wijnand

Calling Buildserviceprovider from application code results in additional copy of singleston services

Greetings, I am currently working on a very old .NET 1.1 core project in .NET 6 and I saw a warning that i found concerning but i am not entirely sure how i can fix this . The guides I found seem to give me the impression this entire function is wrong. services.AddMvc(options => { // Unsure if this works. If it does, it doesn't get the strings from the resource file. // Test when certain this must be triggered var F = services.BuildServiceProvider().GetService<IStringLocalizerFactory>(); var L = F.Create(typeof(ModelBindingMessages)); options.ModelBindingMessageProvider.SetValueIsInvalidAccessor( (x) => L["De waarde {0} is niet geldig voor veld {1}."]); options.ModelBindingMessageProvider.SetValueMustBeANumberAccessor( (x) => L["Het veld {0} moet een nummer zijn."]); options.ModelBindingMessageProvider.SetMissingBindRequiredValueAccessor( (x) => L["Er is geen waarde gegeven aan het veld {0}.", x]); options.ModelBindingMessageProvider.SetAttemptedValueIsInvalidAccessor( (x, y) => L["De waarde {0} is niet geldig voor veld {1}.", x, y]); options.ModelBindingMessageProvider.SetMissingKeyOrValueAccessor( () => L["Een waarde is verplicht."]); options.ModelBindingMessageProvider.SetUnknownValueIsInvalidAccessor( (x) => L["De opgegeven waarde is niet geldig veld {0}", x]); options.ModelBindingMessageProvider.SetValueMustNotBeNullAccessor( (x) => L["De waarde {0} is niet geldig.", x]); }).AddDataAnnotationsLocalization(); // Add data annotation (ErrorMessage) localization
1 Reply
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.