设备初始化
This commit is contained in:
@@ -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 个子 VM,DI 会把同一个 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>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user