Update con servizio singleton x gestione MtcService
This commit is contained in:
@@ -20,13 +20,17 @@ namespace MP.Data
|
||||
//services.TryAddSingleton<IRedisService, RedisService>();
|
||||
//services.TryAddSingleton<IRedisSubscriptionManager, RedisSubscriptionManager>();
|
||||
|
||||
// Repository Singleton
|
||||
services.TryAddSingleton<IMtcSetupRepository, MtcSetupRepository>();
|
||||
|
||||
// Repository Scoped
|
||||
services.TryAddScoped<IMtcSetupRepository, MtcSetupRepository>();
|
||||
services.TryAddScoped<IStatsAggrRepository, StatsAggrRepository>();
|
||||
services.TryAddScoped<IStatsDetailRepository, StatsDetailRepository>();
|
||||
|
||||
// Servizi Singleton
|
||||
services.TryAddSingleton<IMtcSetupService, MtcSetupService>();
|
||||
|
||||
// Servizi Scoped
|
||||
services.TryAddScoped<IMtcSetupService, MtcSetupService>();
|
||||
services.TryAddScoped<IStatsAggrService, StatsAggrService>();
|
||||
services.TryAddScoped<IStatsDetailService, StatsDetailService>();
|
||||
|
||||
|
||||
@@ -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<MpDataService> 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!;
|
||||
|
||||
/// <summary>
|
||||
@@ -3757,11 +3765,16 @@ namespace MP.IOC.Data
|
||||
{
|
||||
bool answ = false;
|
||||
|
||||
//await using var scope = _scopeFactory.CreateAsyncScope();
|
||||
//var mtcService = scope.ServiceProvider.GetRequiredService<IMtcSetupService>();
|
||||
//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<IMtcSetupService>();
|
||||
answ = await mtcService.ReplaceMachineDataAsync(id, dataList);
|
||||
}
|
||||
else
|
||||
{
|
||||
answ = await MtcService.ReplaceMachineDataAsync(id, dataList);
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user