Test Docker
This commit is contained in:
@@ -2,23 +2,37 @@ using Elecciones.Database;
|
||||
using Elecciones.Infrastructure.Services;
|
||||
using Elecciones.Worker;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Serilog;
|
||||
using System.Net.Http;
|
||||
using System.Net.Security;
|
||||
using System.Security.Authentication;
|
||||
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.WriteTo.Console()
|
||||
.CreateBootstrapLogger();
|
||||
|
||||
Log.Information("Iniciando Elecciones.Worker Host...");
|
||||
|
||||
var builder = Host.CreateApplicationBuilder(args);
|
||||
|
||||
// --- Configuración de Servicios ---
|
||||
builder.Services.AddSerilog(config =>
|
||||
config
|
||||
.ReadFrom.Configuration(builder.Configuration)
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.Console()
|
||||
.WriteTo.File("logs/worker-.log", rollingInterval: RollingInterval.Day));
|
||||
|
||||
// 1. Configuración de Base de Datos (¡Este bloque es esencial!)
|
||||
// --- Configuración de Servicios ---
|
||||
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
|
||||
builder.Services.AddDbContext<EleccionesDbContext>(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<IElectoralApiService, FakeElectoralApiService>();
|
||||
#else
|
||||
// En modo RELEASE (producción), usamos el servicio REAL.
|
||||
// --- SECCIÓN MODIFICADA (FINAL) ---
|
||||
builder.Services.AddHttpClient("ElectoralApiClient", client =>
|
||||
{
|
||||
var baseUrl = builder.Configuration["ElectoralApi:BaseUrl"];
|
||||
@@ -26,13 +40,44 @@ builder.Services.AddHttpClient("ElectoralApiClient", client =>
|
||||
{
|
||||
client.BaseAddress = new Uri(baseUrl);
|
||||
}
|
||||
})
|
||||
.ConfigurePrimaryHttpMessageHandler(() =>
|
||||
{
|
||||
return new SocketsHttpHandler
|
||||
{
|
||||
SslOptions = new SslClientAuthenticationOptions
|
||||
{
|
||||
// Forzamos el protocolo TLS 1.3
|
||||
EnabledSslProtocols = SslProtocols.Tls13,
|
||||
|
||||
// --- ¡¡¡LA LÍNEA CLAVE CORREGIDA!!! ---
|
||||
// Forzamos explícitamente los únicos 3 cipher suites que el servidor acepta.
|
||||
CipherSuitesPolicy = new CipherSuitesPolicy(new[]
|
||||
{
|
||||
TlsCipherSuite.TLS_AES_128_GCM_SHA256,
|
||||
TlsCipherSuite.TLS_AES_256_GCM_SHA384,
|
||||
TlsCipherSuite.TLS_CHACHA20_POLY1305_SHA256
|
||||
})
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
builder.Services.AddSingleton<IElectoralApiService, ElectoralApiService>();
|
||||
// --- FIN DE LA SECCIÓN MODIFICADA ---
|
||||
#endif
|
||||
|
||||
// 3. Registrar el Worker como un servicio que se ejecuta en segundo plano.
|
||||
builder.Services.AddHostedService<Worker>();
|
||||
|
||||
|
||||
var host = builder.Build();
|
||||
host.Run();
|
||||
|
||||
try {
|
||||
host.Run();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "El Host de Elecciones.Worker terminó inesperadamente");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Log.CloseAndFlush();
|
||||
}
|
||||
Reference in New Issue
Block a user