wanshenmean
4 天以前 90fa55064597236b9581304f232a607ffc7b730e
fix(WCS): 解决OutboundTaskFlowService与TaskService的循环依赖

使用IComponentContext延迟解析ITaskService,避免构造函数直接注入
导致的Autofac循环依赖检测失败。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
已修改1个文件
18 ■■■■■ 文件已修改
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/Flows/OutboundTaskFlowService.cs 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/Flows/OutboundTaskFlowService.cs
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Autofac;
using Newtonsoft.Json;
using System.Diagnostics.CodeAnalysis;
using WIDESEAWCS_Common.HttpEnum;
using WIDESEAWCS_Common.TaskEnum;
@@ -27,8 +28,8 @@
        private readonly IRouterService _routerService;
        private readonly HttpClientHelper _httpClientHelper;
        private readonly IRobotTaskService _robotTaskService;
        private readonly ITaskService _taskService;
        private readonly ITaskRepository _taskRepository;
        private readonly IComponentContext _componentContext;
        /// <summary>
        /// 初始化出库任务流程服务。
@@ -36,16 +37,21 @@
        /// <param name="routerService">路由服务。</param>
        /// <param name="httpClientHelper">WMS接口调用帮助类。</param>
        /// <param name="robotTaskService">机械手任务服务。</param>
        /// <param name="taskService">任务服务(用于接收入库任务)。</param>
        /// <param name="taskRepository">任务仓储(用于删除出库任务)。</param>
        public OutboundTaskFlowService(IRouterService routerService, HttpClientHelper httpClientHelper, IRobotTaskService robotTaskService, ITaskService taskService, ITaskRepository taskRepository)
        /// <param name="componentContext">Autofac组件上下文(用于延迟解析ITaskService以避免循环依赖)。</param>
        public OutboundTaskFlowService(IRouterService routerService, HttpClientHelper httpClientHelper, IRobotTaskService robotTaskService, ITaskRepository taskRepository, IComponentContext componentContext)
        {
            _routerService = routerService;
            _httpClientHelper = httpClientHelper;
            _robotTaskService = robotTaskService;
            _taskService = taskService;
            _taskRepository = taskRepository;
            _componentContext = componentContext;
        }
        /// <summary>
        /// 延迟解析ITaskService以避免循环依赖
        /// </summary>
        private ITaskService TaskService => _componentContext.Resolve<ITaskService>();
        /// <summary>
        /// 接收WMS任务时初始化出库任务。
@@ -152,7 +158,7 @@
                    _taskRepository.DeleteAndMoveIntoHty(task, OperateTypeEnum.自动完成);
                    // 调用ReceiveWMSTask创建本地入库任务
                    var receiveResult = _taskService.ReceiveWMSTask(new List<WMSTaskDTO> { inboundTaskDto });
                    var receiveResult = TaskService.ReceiveWMSTask(new List<WMSTaskDTO> { inboundTaskDto });
                    if (!receiveResult.Status)
                    {
                        return content.Error($"创建本地入库任务失败: {receiveResult.Message}");