using Elecciones.Database; using Elecciones.Infrastructure.Services; using Elecciones.Worker; using Microsoft.EntityFrameworkCore; var builder = Host.CreateApplicationBuilder(args); // --- Configuración de Servicios --- // 1. Configuración de Base de Datos (¡Este bloque es esencial!) var connectionString = builder.Configuration.GetConnectionString("DefaultConnection"); builder.Services.AddDbContext(options => options.UseSqlServer(connectionString)); // 2. Configuración del Servicio de API (elegirá el Real o el Falso según el modo de compilación) #if DEBUG // En modo DEBUG (desarrollo local), usamos el servicio FALSO. // No es necesario registrar el ILogger, .NET lo inyecta automáticamente. builder.Services.AddSingleton(); #else // En modo RELEASE (producción), usamos el servicio REAL. builder.Services.AddHttpClient("ElectoralApiClient", client => { var baseUrl = builder.Configuration["ElectoralApi:BaseUrl"]; if (!string.IsNullOrEmpty(baseUrl)) { client.BaseAddress = new Uri(baseUrl); } }); builder.Services.AddSingleton(); #endif // 3. Registrar el Worker como un servicio que se ejecuta en segundo plano. builder.Services.AddHostedService(); var host = builder.Build(); host.Run();