From 6483c9fe117b7af45dc2ed35ffd6236fae761e03 Mon Sep 17 00:00:00 2001 From: oysand Date: Thu, 27 Jun 2024 12:58:55 +0200 Subject: [PATCH] Get new robot service before update --- backend/api/EventHandlers/MqttEventHandler.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/api/EventHandlers/MqttEventHandler.cs b/backend/api/EventHandlers/MqttEventHandler.cs index ac85cc1d..224f294b 100644 --- a/backend/api/EventHandlers/MqttEventHandler.cs +++ b/backend/api/EventHandlers/MqttEventHandler.cs @@ -342,7 +342,9 @@ private async void OnIsarMissionUpdate(object? sender, MqttReceivedArgs mqttArgs try { _updateRobotSemaphore.WaitOne(); - await robotService.UpdateCurrentArea(robot.Id, null); + var newProviderToUpdateCurrentArea = GetServiceProvider(); // To ensure that the robot updates the other values correctly, it needs to get a new provider and service + var newRobotServiceToUpdateCurrentArea = newProviderToUpdateCurrentArea.GetRequiredService(); + await newRobotServiceToUpdateCurrentArea.UpdateCurrentArea(robot.Id, null); _updateRobotSemaphore.Release(); } catch (RobotNotFoundException) @@ -355,7 +357,9 @@ private async void OnIsarMissionUpdate(object? sender, MqttReceivedArgs mqttArgs try { _updateRobotSemaphore.WaitOne(); - await robotService.UpdateCurrentMissionId(robot.Id, null); + var newProviderToUpdateCurrentMissionId = GetServiceProvider(); // To ensure that the robot updates the other values correctly, it needs to get a new provider and service + var newRobotServiceToUpdateCurrentMissionId = newProviderToUpdateCurrentMissionId.GetRequiredService(); + await newRobotServiceToUpdateCurrentMissionId.UpdateCurrentMissionId(robot.Id, null); _updateRobotSemaphore.Release(); } catch (RobotNotFoundException)