private static void ConfigureServices(IServiceCollection services) { services.AddSectionOptions <TimeManagerOptions>(Configuration); services.AddSectionOptions <AppManagerOptions>(Configuration); services.AddSectionOptions <SerialPortReceiverOptions>(Configuration); services.AddSectionOptions <SerialPortOptions>(Configuration); services.AddSingleton(sp => new SerialPortSwitch(sp.GetRequiredService <IOptions <SerialPortOptions> >().Value)); #if DEBUG || TEST if (!SerialPortSwitch.IsAnyPortsOnSystem()) { services.AddSingleton <IJettonReceiver, TestReceiver>(); } else { services.AddSingleton <IJettonReceiver, SerialPortReceiver>(); } #else services.AddSingleton <IJettonReceiver, SerialPortReceiver>(); #endif services.AddSingleton <TimeManager>(); services.AddSingleton <AppManager>(); services.AddSingleton <OverlayManager>(); }
public SerialPortReceiver(SerialPortSwitch serialPort, IOptions <SerialPortReceiverOptions> options) { _options = options.Value; _serialPort = serialPort; _serialPort.Switch += SerialPortOnSwitch; _serialPort.Start(); }