设备初始化

This commit is contained in:
hsc
2026-06-10 14:24:45 +08:00
parent 59d047d8e6
commit 5452857299
6 changed files with 60 additions and 20 deletions

View File

@@ -1,3 +1,5 @@
using DeviceCommand.Base;
using DeviceCommand.Device;
using MainModule.Views;
using System.Reflection;
using UIShare.GlobalVariable;
@@ -18,11 +20,6 @@ namespace MainModule
containerRegistry.RegisterForNavigation<MainView>("MainView");
containerRegistry.RegisterForNavigation<AutomatedTestingView>("AutomatedTestingView");
containerRegistry.RegisterForNavigation<ProtocolStartView>("ProtocolStartView");
// Scoped: one ScopedContext per container scope.
// AutomatedTestingViewModel creates its own scope (IContainerExtension.CreateScope)
// and resolves the 5 child VMs from it, so all siblings inside one parent share
// the same ScopedContext, while different parents get isolated instances.
}
}
}

View File

@@ -9,6 +9,7 @@ using UIShare.GlobalVariable;
using UIShare.PubEvent;
using UIShare.UIViewModel;
using UIShare.ViewModelBase;
using static System.Formats.Asn1.AsnWriter;
namespace MainModule.ViewModels
{
@@ -33,6 +34,7 @@ namespace MainModule.ViewModels
public StepRunning _stepRunning { get; }
public GlobalInfo _globalInfo { get; }
public SystemConfig _systemConfig { get; set; }
public DeviceManager _deviceManager { get; set; }
// 5 个子 ViewModel 全部从同一个 scope 解析,自动注入同一个 ScopedContext
public CommandTreeViewModel CommandTreeVM { get; }
@@ -45,15 +47,15 @@ namespace MainModule.ViewModels
public ICommand RefreshCommand { get; set; }
public ICommand BackToProtocolCommand { get; set; }
public AutomatedTestingViewModel(IContainerExtension container) : base(container)
public AutomatedTestingViewModel(IContainerProvider container) : base(container)
{
// 每个 AutomatedTestingViewModel 实例创建独立的容器作用域
_scope = container.CreateScope();
_globalInfo=container.Resolve<GlobalInfo>();
_globalInfo =container.Resolve<GlobalInfo>();
// 在该作用域内解析 ScopedContext —— 当前作用域唯一
_scopedContext = _scope.Resolve<ScopedContext>();
_stepRunning = _scope.Resolve<StepRunning>();
_systemConfig = _scope.Resolve<SystemConfig>();
_systemConfig = _scope.Resolve<SystemConfig>();;
// 关键:从同一个 _scope 解析 5 个子 VMDI 会把同一个 ScopedContext 注入它们
CommandTreeVM = _scope.Resolve<CommandTreeViewModel>();
StepsManagerVM = _scope.Resolve<StepsManagerViewModel>();
@@ -62,6 +64,7 @@ namespace MainModule.ViewModels
ParametersManagerVM = _scope.Resolve<ParametersManagerViewModel>();
RefreshCommand = new DelegateCommand(OnRefresh);
BackToProtocolCommand = new DelegateCommand(OnBackToProtocol);
}
public void Dispose()
@@ -144,6 +147,7 @@ namespace MainModule.ViewModels
_scopedContext.Program.StepCollection = program.StepCollection;
_scopedContext.Program.ErrorStepCollection = program.ErrorStepCollection;
_scopedContext.CurrentFilePath = filePath;
_deviceManager = _scope.Resolve<DeviceManager>();
}
}