using FinlyticAssets.Database; using FinlyticAssets.Services; using FinlyticAssets.Util; using FinlyticCore.Database; using FinlyticCore.Services; using FinlyticCore.Services.TradeRepublic; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; var builder = Host.CreateApplicationBuilder(args); // DB Context builder.Services.AddDbContext(options => options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"))); builder.Services.AddScoped(sp => sp.GetRequiredService()); // Core Services builder.Services.AddSingleton(); builder.Services.AddSingleton(typeof(IFinlyticLogger<>), typeof(FinlyticLogger<>)); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddSingleton(); builder.Services.AddHostedService(sp => sp.GetRequiredService()); builder.Services.AddHostedService(); var host = builder.Build(); using (var scope = host.Services.CreateScope()) { try { var context = scope.ServiceProvider.GetRequiredService(); var connStr = builder.Configuration.GetConnectionString("DefaultConnection") ?? ""; await context.MigrateWithBootstrapAsync(connStr); } catch (Exception ex) { Console.WriteLine($"Critical error during database migration for FinlyticAssets: {ex.Message}"); } } host.Run();