using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Mws.Application.Accounts; using Mws.Application.Auth; using Mws.Application.Common; using Mws.Application.Documents; using Mws.Application.Permissions; using Mws.Application.Projects; using Mws.Application.Roles; using Mws.Application.Tasks; using Mws.Infrastructure.Authentication; using Mws.Infrastructure.Persistence; namespace Mws.Infrastructure; public static class DependencyInjection { public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration) { var connectionString = configuration.GetConnectionString("Default") ?? "Host=localhost;Port=5432;Database=mws;Username=mws;Password=mws"; services.AddDbContext(options => options.UseNpgsql(connectionString)); services.AddScoped(); services.AddAutoMapper(cfg => { }, typeof(MappingProfile).Assembly); services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(IUnitOfWork).Assembly)); services.AddScoped(); var jwtSection = configuration.GetSection("Jwt"); var jwtOptions = jwtSection.Get() ?? new JwtOptions(); if (string.IsNullOrWhiteSpace(jwtOptions.Secret) || jwtOptions.Secret.Length < 32) { jwtOptions.Secret = Environment.GetEnvironmentVariable("MWS_JWT_SECRET") ?? "mws-development-secret-key-change-me-in-production-123456"; } services.Configure(jwtSection.Bind); services.AddSingleton(jwtOptions); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); return services; } }