using System; using Microsoft.Extensions.DependencyInjection; namespace Wabbajack.DTOs; public static class DependencyInjectionExtensions { public static IServiceCollection AddAllSingleton(this IServiceCollection services, Func? ctor = null) where TBase : class, T1 where T1 : class { if (ctor == null) services.AddSingleton(); else services.AddSingleton(ctor); services.AddSingleton(s => s.GetService()!); return services; } public static IServiceCollection AddAllSingleton(this IServiceCollection services, Func? ctor = null) where TBase : class, T1, T2 where T1 : class where T2 : class { if (ctor == null) services.AddSingleton(); else services.AddSingleton(ctor); services.AddSingleton(s => s.GetService()!); services.AddSingleton(s => s.GetService()!); return services; } public static IServiceCollection AddAllSingleton(this IServiceCollection services, Func? ctor = null) where TBase : class, T1, T2, T3 where T1 : class where T2 : class where T3 : class { if (ctor == null) services.AddSingleton(); else services.AddSingleton(ctor); services.AddSingleton(s => s.GetService()!); services.AddSingleton(s => s.GetService()!); services.AddSingleton(s => s.GetService()!); return services; } public static IServiceCollection AddAllSingleton(this IServiceCollection services, Func? ctor = null) where TBase : class, T1, T2, T3, T4 where T1 : class where T2 : class where T3 : class where T4 : class { if (ctor == null) services.AddSingleton(); else services.AddSingleton(ctor); services.AddSingleton(s => s.GetService()!); services.AddSingleton(s => s.GetService()!); services.AddSingleton(s => s.GetService()!); services.AddSingleton(s => s.GetService()!); return services; } }