using Ninject; using Ninject.Extensions.ChildKernel; using System.ComponentModel; using System.Reflection; using VisionBuilder.UI.Common; using VisionBuilder.UI.IOCommander.Interfaces; using VisionBuilder.UI.IOCommander.Modules; using VisionBuilder.UI.IOCommander.Settings; namespace VisionBuilder.UI.IOCommander; public static class ModuleExtensions { public static IKernel UseIOCommander(this IKernel self, string[] cameraNames) { // for settings to work properly TypeDescriptor.AddAttributes(typeof(List), new TypeConverterAttribute(typeof(IOCommanderPinActionListConverter))); TypeDescriptor.AddAttributes(typeof(List), new TypeConverterAttribute(typeof(IOCommanderCommandListConverter))); List cameras = cameraNames.Select(name => new IOCommanderCameraSettings(name)).ToList(); self.Bind().ToConstant(new IOCommanderSettings(cameras.ToArray())); self.Bind().To().InSingletonScope(); self.Bind().To().InSingletonScope(); self.Bind().To().InSingletonScope(); self.Bind().To().InSingletonScope(); return self; } public static IChildKernel UseCameraIOCommander(this IChildKernel self, string cameraName) { var ioCommanderSettings = self.Get(); var cameraSettings=ioCommanderSettings.Cameras.First(x => x.CameraName == cameraName); self.Bind().ToConstant(cameraSettings); self.Bind().To().InSingletonScope(); return self; } }