From e8ea4c58154db95d61a0abc55fe9126b2f2e12c1 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 23 Apr 2026 19:50:59 +0200 Subject: [PATCH] Update con servizio singleton x gestione MtcService --- MP.Data/DataServiceCollectionExtensions.cs | 8 +++++-- MP.IOC/Data/MpDataService.cs | 27 ++++++++++++++++------ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/MP.Data/DataServiceCollectionExtensions.cs b/MP.Data/DataServiceCollectionExtensions.cs index 4ddfc73a..4fa52ee2 100644 --- a/MP.Data/DataServiceCollectionExtensions.cs +++ b/MP.Data/DataServiceCollectionExtensions.cs @@ -20,13 +20,17 @@ namespace MP.Data //services.TryAddSingleton(); //services.TryAddSingleton(); + // Repository Singleton + services.TryAddSingleton(); + // Repository Scoped - services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); + // Servizi Singleton + services.TryAddSingleton(); + // Servizi Scoped - services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); diff --git a/MP.IOC/Data/MpDataService.cs b/MP.IOC/Data/MpDataService.cs index da33ef35..f17fe73d 100644 --- a/MP.IOC/Data/MpDataService.cs +++ b/MP.IOC/Data/MpDataService.cs @@ -6,6 +6,8 @@ using MP.Data; using MP.Data.DbModels; using MP.Data.DbModels.Anag; using MP.Data.MgModels; +using MP.Data.Repository.Mtc; +using MP.Data.Services.Mtc; using Newtonsoft.Json; using NLog; using StackExchange.Redis; @@ -23,7 +25,9 @@ namespace MP.IOC.Data public MpDataService( IConfiguration configuration, ILogger logger, - IServiceScopeFactory scopeFactory) + IServiceScopeFactory scopeFactory, + IMtcSetupRepository mtcRepo, + IMtcSetupService mtcServ) { _logger = logger; _logger.LogInformation("Starting MpDataService INIT"); @@ -57,6 +61,9 @@ namespace MP.IOC.Data _logger.LogInformation("DbControllers INIT OK"); } + MtcRepo = mtcRepo; + MtcService = mtcServ; + // conf mongo... connStr = _configuration.GetConnectionString("mdbConnString"); if (string.IsNullOrEmpty(connStr)) @@ -77,7 +84,8 @@ namespace MP.IOC.Data public static MP.Data.Controllers.MpIocController IocDbController { get; set; } = null!; public static MP.Data.Controllers.MpMongoController mongoController { get; set; } = null!; public static MP.Data.Controllers.MpSpecController SpecDbController { get; set; } = null!; - public static MP.Data.Services.Mtc.IMtcSetupService MtcService { get; set; } = null!; + private static MP.Data.Services.Mtc.IMtcSetupService MtcService = null!; + private static MP.Data.Repository.Mtc.IMtcSetupRepository MtcRepo; public MessagePipe BroadastMsgPipe { get; set; } = null!; /// @@ -3757,11 +3765,16 @@ namespace MP.IOC.Data { bool answ = false; - //await using var scope = _scopeFactory.CreateAsyncScope(); - //var mtcService = scope.ServiceProvider.GetRequiredService(); - //answ = await mtcService.ReplaceMachineDataAsync(id, dataList); - - answ = await MtcService.ReplaceMachineDataAsync(id, dataList); + if (false) + { + await using var scope = _scopeFactory.CreateAsyncScope(); + var mtcService = scope.ServiceProvider.GetRequiredService(); + answ = await mtcService.ReplaceMachineDataAsync(id, dataList); + } + else + { + answ = await MtcService.ReplaceMachineDataAsync(id, dataList); + } return answ; }