I have an application that uses App.config file to store parameters used throughout the application. The parameters represent file names, paths and similar.
The main call looks as following:
CsvExtractor.ExtractDataAndCopyFiles();
...
public class CsvExtractor
{
public static void ExtractDataAndCopyFiles()
{
var eventList = DataReader.ReadInputCsvFile(ExtractorParams.InputCsvFile, ExtractorParams.SheetName);
DataWriter.WriteOutputCsvFile(
ExtractorParams.OutputCsvFile,
CreateExtractData(eventList),
ExtractorParams.EventFolder,
ExtractorParams.BlobFolder,
ExtractorParams.MissingFiles);
}
...
}
What is correct approach:
1) Use the separate class as following:
public class ExtractorParams
{
public static string InputCsvFile
{
get { return ConfigurationManager.AppSettings["InputCsvFile"]; }
}
public static string SheetName
{
get { return ConfigurationManager.AppSettings["SheetName"]; }
}
public static string EventFolder
{
get { return ConfigurationManager.AppSettings["EventFolder"]; }
}
public static string BlobFolder
{
get { return ConfigurationManager.AppSettings["BlobFolder"]; }
}
public static string OutputCsvFile
{
get { return ConfigurationManager.AppSettings["OutputCsvFile"]; }
}
public static string MissingFiles
{
get { return ConfigurationManager.AppSettings["MissingFiles"]; }
}
}
And use it when needed as above.
Or:
2) Use the array of parameters as following:
CsvExtractor.ExtractDataAndCopyFiles(list_of_params);
...
public class CsvExtractor
{
public static void ExtractDataAndCopyFiles(params string[] list)
{
...
}
...
}
option 1) +1 But in my project we did something like this
we saved a value from config file in the static variable. when it needed we get it from this variable.