using ColaFlow.Modules.Identity.Application.Services; using ColaFlow.Modules.Identity.Domain.Repositories; using ColaFlow.Modules.Identity.Infrastructure.Persistence; using ColaFlow.Modules.Identity.Infrastructure.Persistence.Repositories; using ColaFlow.Modules.Identity.Infrastructure.Services; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; namespace ColaFlow.Modules.Identity.Infrastructure; public static class DependencyInjection { public static IServiceCollection AddIdentityInfrastructure( this IServiceCollection services, IConfiguration configuration, IHostEnvironment? environment = null) { // Only register PostgreSQL DbContext in non-Testing environments // In Testing environment, WebApplicationFactory will register InMemory provider if (environment == null || environment.EnvironmentName != "Testing") { // DbContext (using connection string) services.AddDbContext(options => options.UseNpgsql( configuration.GetConnectionString("DefaultConnection"), b => b.MigrationsAssembly(typeof(IdentityDbContext).Assembly.FullName))); } // Tenant Context (Scoped - one instance per request) services.AddScoped(); services.AddHttpContextAccessor(); // Required for HttpContext access // Repositories services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); // Application Services services.AddScoped(); services.AddScoped(); services.AddScoped(); return services; } }