I'm not quite sure what you are doing here. Could you make the dictionary a public property of this class?
Well, one option is to use a public property, and then create one instance of this class when initializing your application (this will populate your dictionary if you populate it in your class constructor), and then you can pass the same instance to functions or class constructors without need to read the external file again.
public class ReadFileClass {
Having done this, you can use only one instance of the object to populate the settings dictionary, and then simply pass it on. I have used this method many times to avoid multiple accesses to a database or file, which can have a costly performance impact. If you want to use a class that contains settings in a different file than the one that creates it, you simply force the class constructor to treat it as a parameter.
source share