Fix avvio API con scope corretto servizi DB
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>1.1.2603.1410</Version>
|
||||
<Version>1.1.2603.1411</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
+14
-9
@@ -155,18 +155,12 @@ builder.Services.AddDbContext<DataLayerContext>(options =>
|
||||
.LogTo(_ => { }); // disabilita EF logging;
|
||||
});
|
||||
|
||||
//builder.Services.AddSingleton<DataLayerServices>();
|
||||
builder.Services.AddSingleton<DataLayerServices>();
|
||||
// altri servizi!
|
||||
builder.Services.AddSingleton<ImageCacheService>();
|
||||
builder.Services.AddSingleton<ExternalMessageProcessor>();
|
||||
builder.Services.AddHostedService<RedisSubscriberService>();
|
||||
builder.Services.AddSingleton<ConfigDataService>();
|
||||
builder.Services.AddSingleton<ProdService>();
|
||||
// servizi Scoped (usano DB)
|
||||
|
||||
//builder.Services.AddSingleton<DataLayerServices>();
|
||||
builder.Services.AddScoped<DataLayerServices>();
|
||||
// Repository con interfaccia
|
||||
builder.Services.AddScoped<IGenClassRepository, GenClassRepository>();
|
||||
|
||||
// Servizi dati con interfaccia
|
||||
builder.Services.AddScoped<IGenClassService, GenClassService>();
|
||||
|
||||
@@ -188,6 +182,17 @@ builder.Services.Scan(scan => scan
|
||||
);
|
||||
#endif
|
||||
|
||||
// servizi Singleton (no DB)
|
||||
builder.Services.AddSingleton<ImageCacheService>();
|
||||
builder.Services.AddSingleton<ConfigDataService>();
|
||||
builder.Services.AddSingleton<ProdService>();
|
||||
|
||||
// servizi con dipendenze" ma Scoped
|
||||
builder.Services.AddScoped<ExternalMessageProcessor>();
|
||||
|
||||
// servizi hosted usano scope factory
|
||||
builder.Services.AddHostedService<RedisSubscriberService>();
|
||||
|
||||
// init servizio gestone ReqIndex
|
||||
string cleanupDayTTL = configuration.GetValue<string>("ServerConf:CleanupDayTTL") ?? "360";
|
||||
string rBaseKey = configuration.GetValue<string>("ServerConf:RedisBaseKey") ?? "Lux";
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using EgwCoreLib.Lux.Data.Services;
|
||||
using EgwCoreLib.Lux.Data;
|
||||
|
||||
namespace Lux.API.Services
|
||||
{
|
||||
public class RedisSubscriberService : BackgroundService
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
#if false
|
||||
public RedisSubscriberService(IConfiguration config, RedisSubscriptionManager subManager, ExternalMessageProcessor processor)
|
||||
{
|
||||
_subManager = subManager;
|
||||
@@ -15,9 +14,6 @@ namespace Lux.API.Services
|
||||
chSub = _config.GetValue<string>("ServerConf:ChannelSub") ?? "";
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected override Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
@@ -29,15 +25,44 @@ namespace Lux.API.Services
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IConfiguration _config;
|
||||
private readonly ExternalMessageProcessor _processor;
|
||||
private readonly RedisSubscriptionManager _subManager;
|
||||
private readonly string chSub = "";
|
||||
#endif
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
private readonly IConfiguration _config;
|
||||
private readonly RedisSubscriptionManager _subManager;
|
||||
private readonly IServiceScopeFactory _scopeFactory;
|
||||
private readonly string _channel;
|
||||
|
||||
public RedisSubscriberService(
|
||||
IConfiguration config,
|
||||
RedisSubscriptionManager subManager,
|
||||
IServiceScopeFactory scopeFactory)
|
||||
{
|
||||
_config = config;
|
||||
_subManager = subManager;
|
||||
_scopeFactory = scopeFactory;
|
||||
|
||||
_channel = _config.GetValue<string>("ServerConf:ChannelSub") ?? "";
|
||||
}
|
||||
|
||||
protected override Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
_subManager.Subscribe(_channel, async (ch, msg) =>
|
||||
{
|
||||
// Ogni messaggio → nuovo scope
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
|
||||
var processor = scope.ServiceProvider.GetRequiredService<ExternalMessageProcessor>();
|
||||
|
||||
await processor.HandleResultMessageAsync($"{ch}", $"{msg}");
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>aspnet-Lux.UI-a758c101-a2f4-4e38-977d-1c4887dbbd50</UserSecretsId>
|
||||
<Version>1.1.2603.1410</Version>
|
||||
<Version>1.1.2603.1411</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>LUX - Web Windows MES</i>
|
||||
<h4>Versione: 1.1.2603.1410</h4>
|
||||
<h4>Versione: 1.1.2603.1411</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
1.1.2603.1410
|
||||
1.1.2603.1411
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>1.1.2603.1410</version>
|
||||
<version>1.1.2603.1411</version>
|
||||
<url>http://nexus.steamware.net/repository/SWS/GPW/stable/GPW.UI.zip</url>
|
||||
<changelog>http://nexus.steamware.net/repository/SWS/GPW/stable/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
Reference in New Issue
Block a user