using FluentValidation; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using SeaHaven.Services.Configuration; using System.Reflection; namespace SeaHaven.Services.DependencyInjection { public static class ServicesModule { private static readonly List ExcludedTypes = new(); public static IServiceCollection AddBusinessServices(this IServiceCollection services, IConfiguration configuration) { services.Configure(configuration); services.Configure(configuration.GetSection(JwtOptions.SectionName)); services.Configure(configuration.GetSection(ApprovalsOptions.SectionName)); services.Configure(configuration.GetSection(VendorPortalOptions.SectionName)); services.Configure(configuration.GetSection(VendorDocumentsOptions.SectionName)); var assembly = Assembly.GetExecutingAssembly(); var allClasses = assembly.GetTypes() .Where(t => t.IsClass && !t.IsAbstract && !t.IsGenericType && !ExcludedTypes.Contains(t)) .ToList(); foreach (var implementationType in allClasses) { var defaultInterface = implementationType.GetInterfaces() .FirstOrDefault(i => i.Name == $"I{implementationType.Name}"); if (defaultInterface != null) { services.AddScoped(defaultInterface, implementationType); } } services.AddValidatorsFromAssembly(assembly); return services; } } }