I am trying to find the best way to initialise device drivers (maintained by production staff). Configuration generally contains serial ports and other information which production staff may need to change if the underlying hardware for the device driver changes.
e.g.
using System.IO.Ports;
public class Scanner : IDriver
{
public SerialPort SerialPort { get; private set; }
public String Id { get; private set; }
public String DisplayName { get; private set; }
public Scanner(SerialPort serialPort, String id, String displayName)
{
SerialPort = serialPort;
Id = id;
DisplayName = displayName;
}
}
public class TestMethod
{
public Scanner MainScanner { get; private set; }
public Scanner SecondaryScanner { get; private set; }
public TestMethod (Scanner main, Scanner secondary)
{
MainScanner = main;
SecondaryScanner = secondary;
}
}
How can I use a DI container and still make the configuration changeable at runtime? I would like to avoid using the XML configuration that comes with the DI containers as I expect the production staff to modify these (configuration) files often. A separate configuration file would be prefered.
A possible implementation of xml configuration
<DeviceDrivers>
<Driver name="main" id="IX234" displayName="main scanner">
<SerialPort name="serialPort" portName="COM8" baudRate="11560" parity="None" dataBits="8" stopBits="None">
</Driver>
<Driver name="secondary" id="IX2E3" displayName="secondary scanner">
<SerialPort name="serialPort" portName="COM9" baudRate="11560" parity="None" dataBits="8" stopBits="None">
</Driver>
</DeviceDrivers>
SerialPort
itself need to be intialised from the configuration file.
Thanks
PS: I was considering Ninject, but not sure if I can pull this off.