ASP.NET Core resource files without a culture in the file name, why not?

Viewed 383

Quote from ASP.NET Microsoft Docs

If you create a resource file in Visual Studio without a culture in the file name (for example, Welcome.resx), Visual Studio will create a C# class with a property for each string. That's usually not what you want with ASP.NET Core. You typically don't have a default .resx resource file (a .resx file without the culture name). We suggest you create the .resx file with a culture name (for example Welcome.fr.resx). When you create a .resx file with a culture name, Visual Studio won't generate the class file.

IMO the doc doesn't explain clearly why having a C# class with property names is NOT what you want with ASP.NET Core. It seems more convenient to use a property in a static class than to have to inject IStringLocalizer everywhere. Can anyone please elaborate??

1 Answers

In my opinion, asp.net core is dependency injection based application, normally, for all the class, we will use dependency injection. This will make our application achieve Inversion of Control (IoC) between classes and their dependencies. Normally, we will not usea property in a static class in asp.net core.

Details, you could refer to this article.

This is the reason why the doc suggest you to use e Welcome.fr.resx instead of Welcome.resx in yout application.

Related