72 lines
2.2 KiB
C#
72 lines
2.2 KiB
C#
using System.Security.Cryptography.X509Certificates;
|
|
using Registration.Infra.Repositories;
|
|
using Registration.API.Configuration;
|
|
using Registration.API.Services;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddSwaggerGen();
|
|
builder.Services.AddScoped<IMemberRepository, MemberRepository>();
|
|
|
|
var relayOptions = builder.Configuration.GetSection("VbytesRelay").Get<VbytesRelayOptions>()
|
|
?? throw new InvalidOperationException("VbytesRelay configuration section is missing.");
|
|
|
|
builder.Services.Configure<VbytesRelayOptions>(builder.Configuration.GetSection("VbytesRelay"));
|
|
|
|
|
|
var certificate = X509CertificateLoader.LoadPkcs12FromFile(
|
|
relayOptions.ClientCertificatePfxPath, password: null);
|
|
|
|
builder.Services.AddHttpClient(VbytesParticipantRelayService.HttpClientName, client =>
|
|
{
|
|
client.BaseAddress = new Uri(relayOptions.BaseUrl);
|
|
client.Timeout = TimeSpan.FromSeconds(30);
|
|
})
|
|
.ConfigurePrimaryHttpMessageHandler(() =>
|
|
{
|
|
var handler = new HttpClientHandler();
|
|
handler.ClientCertificates.Add(certificate);
|
|
return handler;
|
|
});
|
|
|
|
builder.Services.AddScoped<IVbytesParticipantRelayService, VbytesParticipantRelayService>();
|
|
builder.Services.AddScoped<IVbytesVolunteerRelayService, VbytesVolunteerRelayService>();
|
|
|
|
var authApiOptions = builder.Configuration.GetSection("AuthApi").Get<AuthApiOptions>()
|
|
?? throw new InvalidOperationException("AuthApi configuration section is missing.");
|
|
|
|
builder.Services.Configure<AuthApiOptions>(builder.Configuration.GetSection("AuthApi"));
|
|
builder.Services.AddHttpClient(AuthService.HttpClientName, client =>
|
|
{
|
|
client.BaseAddress = new Uri(authApiOptions.BaseUrl);
|
|
client.Timeout = TimeSpan.FromSeconds(10);
|
|
});
|
|
builder.Services.AddScoped<IAuthService, AuthService>();
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
var app = builder.Build();
|
|
|
|
using (var scope = app.Services.CreateScope())
|
|
{
|
|
var repo = scope.ServiceProvider.GetRequiredService<IMemberRepository>();
|
|
await repo.EnsureCreated();
|
|
}
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
}
|
|
|
|
if (!app.Environment.IsDevelopment())
|
|
{
|
|
app.UseHttpsRedirection();
|
|
}
|
|
|
|
app.UseAuthorization();
|
|
app.MapControllers();
|
|
|
|
app.Run();
|