feat(sentiment): add persistent sentiment entities, summaries, SentimentDbService and MQTT RPC refactoring
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user