feat(sentiment): add persistent sentiment entities, summaries, SentimentDbService and MQTT RPC refactoring

This commit is contained in:
2026-08-24 21:35:48 +02:00
parent 600ccf299e
commit 12e7b57b16
24 changed files with 1510 additions and 1300 deletions
+6 -5
View File
@@ -11,7 +11,7 @@ using Microsoft.Extensions.Hosting;
var builder = Host.CreateApplicationBuilder(args);
// Register PostgreSQL DbContext for settings persistence
// Register PostgreSQL DbContext for sentiment data & settings
builder.Services.AddDbContext<SentimentDbContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddScoped<ISettingsDbContext>(sp => sp.GetRequiredService<SentimentDbContext>());
@@ -23,10 +23,9 @@ builder.Services.AddSingleton(typeof(IFinlyticLogger<>), typeof(FinlyticLogger<>
// Register HttpClient
builder.Services.AddHttpClient();
// Register Service interfaces and co-located implementations
builder.Services.AddScoped<ISettingsDbService, SettingsDbService>();
// Register Sentiment Services
builder.Services.AddScoped<ISentimentDbService, SentimentDbService>();
builder.Services.AddSingleton<IFinBertAnalyzerService, FinBertAnalyzerService>();
builder.Services.AddSingleton<ISentimentStorageService, SentimentStorageService>();
// Register MQTT Client (as singleton hosted service)
builder.Services.AddSingleton<SentimentMqttClient>();
@@ -43,12 +42,14 @@ using (var scope = host.Services.CreateScope())
try
{
var db = scope.ServiceProvider.GetRequiredService<SentimentDbContext>();
await db.Database.MigrateAsync();
var connStr = builder.Configuration.GetConnectionString("DefaultConnection") ?? "";
await db.MigrateWithBootstrapAsync(connStr);
}
catch (Exception ex)
{
Console.WriteLine($"Critical error during database migration for FinlyticSentiment: {ex.Message}");
}
}
await host.RunAsync();