C # console application script / store
What would be the best way to implement the psuedo-session / local storage class in a console application? Basically, when the application starts, I will take a few arguments that I want to make available to each class while the application is running. I thought I could just create a static class and initialize the values when the application starts, but is there a more elegant way?
I usually create a static class called "ConfigurationCache" (or something like that) that can be used to provide application configuration settings.
Keep in mind that you don't want to get too carried away with globals. I seriously recommend taking a look at your design and passing only what you need via method parameters. You must be such that each method receives a parameter for whatever is needed (see Code Complete 2 - Steve McConnell).
This does not mean that the static class is wrong, but ask yourself why you need to pass parameters to your various classes and methods.
a source to share
If you want to take command line arguments (or some other super-duper setting) and put them somewhere that your application can see, I don't know why you think it is "inelegant" to put them in a static class when the application starts ... This is similar to what you want to do.
a source to share
Think of your data as a configuration file required by all of your classes. The file will be accessible from every class, so there is nothing wrong with exposing the data to a static class.
But every class needs to know the path to the configuration file, and changing the path will affect many classes. (Of course, a path should be better than a constant in only one class, which is referenced by all classes rewriting the path.) Thus, the best solution would be to create a class that encapsulates access to the configuartion file. Now each class can create an instance of this class and access the configuration data of the file. Since your data is not supported by the file, you will need to create something like a monostat.
Now you can start thinking about chaining classes. This is important for you? Are you planning to write a unit test and have to mock the config data? Yes? In this case, you should start thinking about using dependency injection and interace-only data access.
So I suggest using dependency injection with an interface, and I would implement the interface with the monostate pattern.
a source to share