using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using SPMS.Application.Interfaces; using SPMS.Application.Settings; using SPMS.Domain.Interfaces; using SPMS.Infrastructure.Auth; using SPMS.Infrastructure.Caching; using SPMS.Infrastructure.Messaging; using SPMS.Infrastructure.Persistence; using SPMS.Infrastructure.Push; using SPMS.Infrastructure.Persistence.Repositories; using SPMS.Infrastructure.Security; using SPMS.Infrastructure.Services; using SPMS.Infrastructure.Webhook; using SPMS.Infrastructure.Workers; namespace SPMS.Infrastructure; public static class DependencyInjection { public static IServiceCollection AddInfrastructure( this IServiceCollection services, IConfiguration configuration) { // DbContext var connectionString = configuration.GetConnectionString("DefaultConnection"); services.AddDbContext(options => options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString))); // UnitOfWork & Repositories services.AddScoped(); services.AddScoped(typeof(IRepository<>), typeof(Repository<>)); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); // External Services services.AddScoped(); services.AddSingleton(); services.AddSingleton(); // File Storage services.AddSingleton(); // Redis services.Configure(configuration.GetSection(RedisSettings.SectionName)); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); // RabbitMQ services.Configure(configuration.GetSection(RabbitMQSettings.SectionName)); services.AddSingleton(); services.AddSingleton(); services.AddHostedService(sp => sp.GetRequiredService()); services.AddScoped(); // Push Senders services.AddSingleton(); services.AddHttpClient("ApnsSender") .ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler { EnableMultipleHttp2Connections = true }); services.AddSingleton(); // Webhook services.AddHttpClient("Webhook"); services.AddSingleton(); // Workers services.AddHostedService(); services.AddHostedService(); services.AddHostedService(); services.AddHostedService(); // Token Store & Email Service services.AddMemoryCache(); services.AddSingleton(); services.AddSingleton(); return services; } }