using Govor.API.Common.Mapping; using Govor.API.Common.SignalR.Helpers; using Govor.API.Hubs.Infrastructure; using Govor.Application.Authentication; using Govor.Application.Authentication.JWT; using Govor.Application.Friends; using Govor.Application.Groups; using Govor.Application.Infrastructure.AdminsStuff; using Govor.Application.Infrastructure.Extensions; using Govor.Application.Infrastructure.Validators; using Govor.Application.Medias; using Govor.Application.Messages; using Govor.Application.PingHandler; using Govor.Application.PrivateUserChats; using Govor.Application.Profiles; using Govor.Application.PushNotifications; using Govor.Application.PushNotifications.Providers; using Govor.Application.Storage; using Govor.Application.Synching; using Govor.Application.Users; using Govor.Application.Users.UserOnlineStatus; using Govor.Application.Users.UserSessions; using Govor.Application.Users.UserSessions.Crypto; using Govor.Domain; using Microsoft.EntityFrameworkCore; namespace Govor.API.Common.Extensions; public static class ConfigurationProgramExtensions { public static void AddServices(this IServiceCollection services) { services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); // Friends services services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(sp => { var env = sp.GetRequiredService(); return new LocalStorageService(env.ContentRootPath); }); services.AddHttpContextAccessor(); // it's very important for CurrentUserService services.AddScoped(); services.AddScoped(); services.AddMemoryCache(); services.AddScoped(); services.AddScoped(); //services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); // User services.AddScoped(); // UserSession services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddSingleton(); // Hubs Infrastructure services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddSingleton(); // Pushs services.AddScoped(); services.AddScoped(); services.AddSingleton(); // Auto Mapper services.AddAutoMapper(typeof(MappingProfile)); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); } public static void AddGovorDbContext(this IServiceCollection services, IConfiguration configuration) { var useMySql = configuration.GetValue("UseMySql"); if (useMySql) { services.AddDbContext(options => { var connectionString = configuration.GetConnectionString(nameof(GovorDbContext)); options.UseMySql( connectionString, new MySqlServerVersion(new Version(8, 0, 21)), mySqlOptions => { mySqlOptions.EnableRetryOnFailure( maxRetryCount: 5, maxRetryDelay: TimeSpan.FromSeconds(5), errorNumbersToAdd: null); }); options.EnableSensitiveDataLogging(); options.EnableDetailedErrors(); }); } else { services.AddDbContext(options => { options.UseNpgsql( configuration.GetConnectionString(nameof(GovorDbContext)), npgsqlOptions => { // retry for transient failures npgsqlOptions.EnableRetryOnFailure( maxRetryCount: 5, maxRetryDelay: TimeSpan.FromSeconds(5), errorCodesToAdd: null); }); //options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking); options.EnableSensitiveDataLogging(); options.EnableDetailedErrors(); }); } } }