diff --git a/src/api/SIGCM2.Application/DependencyInjection.cs b/src/api/SIGCM2.Application/DependencyInjection.cs index b529db7..433a218 100644 --- a/src/api/SIGCM2.Application/DependencyInjection.cs +++ b/src/api/SIGCM2.Application/DependencyInjection.cs @@ -2,6 +2,8 @@ using FluentValidation; using Microsoft.Extensions.DependencyInjection; using SIGCM2.Application.Abstractions; using SIGCM2.Application.Auth.Login; +using SIGCM2.Application.Auth.Logout; +using SIGCM2.Application.Auth.Refresh; namespace SIGCM2.Application; @@ -9,10 +11,12 @@ public static class DependencyInjection { public static IServiceCollection AddApplication(this IServiceCollection services) { - // Register command handlers + // Command handlers services.AddScoped, LoginCommandHandler>(); + services.AddScoped, RefreshCommandHandler>(); + services.AddScoped, LogoutCommandHandler>(); - // Register FluentValidation validators from this assembly + // FluentValidation validators (scans entire Application assembly) services.AddValidatorsFromAssemblyContaining(); return services; diff --git a/src/api/SIGCM2.Infrastructure/DependencyInjection.cs b/src/api/SIGCM2.Infrastructure/DependencyInjection.cs index 858e6bd..9d4d98d 100644 --- a/src/api/SIGCM2.Infrastructure/DependencyInjection.cs +++ b/src/api/SIGCM2.Infrastructure/DependencyInjection.cs @@ -1,5 +1,6 @@ using System.Security.Cryptography; using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; @@ -7,6 +8,8 @@ using Microsoft.IdentityModel.Tokens; using SIGCM2.Application.Abstractions; using SIGCM2.Application.Abstractions.Persistence; using SIGCM2.Application.Abstractions.Security; +using SIGCM2.Application.Auth; +using SIGCM2.Infrastructure.Http; using SIGCM2.Infrastructure.Messaging; using SIGCM2.Infrastructure.Persistence; using SIGCM2.Infrastructure.Security; @@ -24,12 +27,24 @@ public static class DependencyInjection ?? throw new InvalidOperationException("Missing ConnectionStrings:SqlServer"); services.AddSingleton(new SqlConnectionFactory(connectionString)); services.AddScoped(); + services.AddScoped(); // JWT Options — bound lazily via IOptions so tests can override via ConfigureWebHost services.Configure(configuration.GetSection("Jwt")); // Also expose as JwtOptions directly for convenience (resolves via IOptions) services.AddSingleton(sp => sp.GetRequiredService>().Value); + // AuthOptions (Application layer) — populated from the same Jwt config section + services.AddSingleton(sp => + { + var opts = sp.GetRequiredService(); + return new AuthOptions + { + AccessTokenMinutes = opts.AccessTokenMinutes, + RefreshTokenDays = opts.RefreshTokenDays, + }; + }); + // RSA key pair — loaded lazily as singletons from the fully-resolved JwtOptions services.AddSingleton(sp => { @@ -46,6 +61,9 @@ public static class DependencyInjection services.AddScoped(sp => new JwtService(sp.GetRequiredService(), sp.GetRequiredService())); services.AddScoped(); + services.AddSingleton(); + services.AddHttpContextAccessor(); + services.AddScoped(); // Dispatcher services.AddScoped(); diff --git a/tests/SIGCM2.TestSupport/TestWebAppFactory.cs b/tests/SIGCM2.TestSupport/TestWebAppFactory.cs index 6482080..5b134a8 100644 --- a/tests/SIGCM2.TestSupport/TestWebAppFactory.cs +++ b/tests/SIGCM2.TestSupport/TestWebAppFactory.cs @@ -38,6 +38,7 @@ public sealed class TestWebAppFactory : WebApplicationFactory, IAsyncLi ["Jwt:Issuer"] = "sigcm2.api", ["Jwt:Audience"] = "sigcm2.web", ["Jwt:AccessTokenMinutes"] = "60", + ["Jwt:RefreshTokenDays"] = "7", ["Jwt:PrivateKeyPath"] = PrivateKeyPath, ["Jwt:PublicKeyPath"] = PublicKeyPath, ["Jwt:PrivateKey"] = null,