using Managing.Application; using Managing.Application.Abstractions; using Managing.Application.Abstractions.Repositories; using Managing.Application.Abstractions.Services; using Managing.Application.Accounts; using Managing.Application.Backtests; using Managing.Application.ManageBot; using Managing.Application.MoneyManagements; using Managing.Application.Scenarios; using Managing.Application.Shared; using Managing.Application.Synth; using Managing.Application.Trading; using Managing.Application.Trading.Commands; using Managing.Application.Trading.Handlers; using Managing.Application.Users; using Managing.Application.Workers; using Managing.Domain.Trades; using Managing.Infrastructure.Databases; using Managing.Infrastructure.Databases.InfluxDb; using Managing.Infrastructure.Databases.InfluxDb.Abstractions; using Managing.Infrastructure.Databases.InfluxDb.Models; using Managing.Infrastructure.Databases.PostgreSql; using Managing.Infrastructure.Databases.PostgreSql.Configurations; using Managing.Infrastructure.Evm; using Managing.Infrastructure.Evm.Abstractions; using Managing.Infrastructure.Evm.Models.Privy; using Managing.Infrastructure.Evm.Services; using Managing.Infrastructure.Evm.Subgraphs; using Managing.Infrastructure.Exchanges; using Managing.Infrastructure.Exchanges.Abstractions; using Managing.Infrastructure.Exchanges.Exchanges; using Managing.Infrastructure.Messengers.Discord; using Managing.Infrastructure.Storage; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; namespace Managing.Bootstrap; public static class WorkersBootstrap { public static IServiceCollection RegisterWorkersDependencies(this IServiceCollection services, IConfiguration configuration) { return services .AddApplication() .AddInfrastructure(configuration) .AddWorkers(configuration); } private static IServiceCollection AddApplication(this IServiceCollection services) { services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddTransient, OpenPositionCommandHandler>(); services.AddTransient, ClosePositionCommandHandler>(); // Processors services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddSingleton(); services.AddSingleton(); return services; } private static IServiceCollection AddWorkers(this IServiceCollection services, IConfiguration configuration) { // Price Workers if (configuration.GetValue("WorkerPricesFifteenMinutes", false)) { services.AddHostedService(); } if (configuration.GetValue("WorkerPricesOneHour", false)) { services.AddHostedService(); } if (configuration.GetValue("WorkerPricesFourHours", false)) { services.AddHostedService(); } if (configuration.GetValue("WorkerPricesOneDay", false)) { services.AddHostedService(); } if (configuration.GetValue("WorkerPricesFiveMinutes", false)) { services.AddHostedService(); } if (configuration.GetValue("WorkerSpotlight", false)) { services.AddHostedService(); } if (configuration.GetValue("WorkerTraderWatcher", false)) { services.AddHostedService(); } if (configuration.GetValue("WorkerLeaderboard", false)) { services.AddHostedService(); } if (configuration.GetValue("WorkerFundingRatesWatcher", false)) { services.AddHostedService(); } if (configuration.GetValue("WorkerGeneticAlgorithm", false)) { services.AddHostedService(); } if (configuration.GetValue("WorkerBundleBacktest", false)) { services.AddHostedService(); } return services; } private static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration) { // Database services.AddSingleton(sp => sp.GetRequiredService>().Value); services.AddSingleton(sp => sp.GetRequiredService>().Value); services.AddTransient(); services.AddSingleton(sp => sp.GetRequiredService>().Value); // Evm services.AddUniswapV2(); services.AddGbcFeed(); services.AddChainlink(); services.AddChainlinkGmx(); services.AddSingleton(); // Repositories services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); // Cache services.AddDistributedMemoryCache(); services.AddTransient(); services.AddTransient(); // Processors services.AddTransient(); // Web Clients services.AddTransient(); services.AddTransient(); services.AddSingleton(); services.AddSingleton(); // Web3Proxy Configuration services.Configure(configuration.GetSection("Web3Proxy")); services.AddTransient(); // Http Clients services.AddHttpClient(); // Messengers services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); return services; } }