I’ve got a ConfigurationReader class that I’m trying to wire up using StructureMap or AutoFac (I haven’t settled on which container I’m using).
public class ConfigurationReader {
private string _filePath;
public ConfigurationReader(string filePath){
this._filePath = filePath;
}
public IList<Baz> ListStuff(){
//do something with _filePath;
}
}
There will be 1..n to instances of this class based on how the app is configured (web.config will contain a delimited list of files). I’m looking for an extension point in either IoC container that would allow me to leverage them to create instances of ConfigurationReader.
Well, in AutoFac you can just register each one in the Container (during
Application_Startfor example).Whenever you need to read all configurations you can add a dependency to
IEnumerable<ConfigurationReader>(orIConfigurationReaderif you decide to extract an interface) and it will provide you with all of them.Something like this:
If you extract interfaces, then you may want to register by adding the
.AsImplementedInterfaces()or.As<IConfigurationReader>()at end as well.