We have seen in a previous article how to localize our application thanks to resources. Now here is a little trick to use these resources in a class where you can’t do dependency injection of the localization service.
Using ResourceManager
Just declare a variable of System.Resources.ResourceManger with 2 parameters:
- baseName : The “path” of your targeted resource file
- assembly
If my resource structure is like this:
![](https://www.peug.net/wp-content/uploads/2022/02/path-of-resources-1.png)
Then the code will be :
System.Resources.ResourceManager rm = new( "PlanningWeb.Resources.PDF.report", System.Reflection.Assembly.GetExecutingAssembly() );
string myString = rm.GetString("myTitle");