What are the advantages/disadvantages of the following approaches for injecting configuration information into a newly constructed instance? Which would you use?
interface IApplicationConfiguration {
string SourcePath { get; }
string DestinationPath { get; }
}
Option one:
class DailyFilePathProvider {
private readonly string sourcePath;
private readonly string destinationPath;
public DailyFilePathProvider(string sourcePath, string destinationPath) {
this.sourcePath = sourcePath;
this.destinationPath = destinationPath;
}
}
var configuration = container.Resolve<IApplicationConfiguration>();
var provider = new DailyFilePathProvider(configuration.SourcePath, configuration.DestinationPath);
Option two:
class DailyFilePathProvider {
private readonly string sourcePath;
private readonly string destinationPath;
public DailyFilePathProvider(IApplicationConfiguration configuration) {
this.sourcePath = configuration.SourcePath;
this.destinationPath = configuration.DestinationPath;
}
}
var configuration = container.Resolve<IApplicationConfiguration>();
var provider = new DailyFilePathProvider(configuration);
Thanks for all thoughts.