0

I call the string in appsettings.json file using these 2 lines:

            var config =  AppSettings.InitConfiguration();
            var name = config["SomeProperties:Name"];

Ideally I would like to make the var config a global variable in each of my class files but haven't got a clue. I just want to use one line so i can call whatever setting I want for simplicity, any help?

MrRabbit
  • 21
  • 7
  • Why do you want to “make the var config a global variable”? What good do you think that will do? – Dour High Arch May 13 '21 at 16:46
  • It is impossible since C# is a true OOP language (not pure), you must use a static dedicated class. I recommend that you create as many static classes as there are domains in order to respect the principle of segregation and more particularly the SOLID Single responsibility principle. For example, separate a `ApplicationParameters`, `FolderPaths`, `Translations`, `SystemStatistics`, `ShellIcons`... –  May 13 '21 at 16:48
  • 1
    A much better option would be using dependency injection. – insane_developer May 13 '21 at 16:49
  • Also you can by default use the `Program` class as `static` if you have few or a handul of "very" global vars to put in. The easiest way. The `Main` being the "highest global" method... –  May 13 '21 at 17:06

0 Answers0