2026-05-14 11:00:12 -05:00
|
|
|
using FluentValidation;
|
2026-07-24 17:35:34 -03:00
|
|
|
using Microsoft.Extensions.Configuration;
|
2026-05-14 11:00:12 -05:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2026-07-24 17:35:34 -03:00
|
|
|
using SeaHaven.Services.Configuration;
|
2026-05-14 11:00:12 -05:00
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
|
|
namespace SeaHaven.Services.DependencyInjection
|
|
|
|
|
{
|
|
|
|
|
public static class ServicesModule
|
|
|
|
|
{
|
|
|
|
|
private static readonly List<Type> ExcludedTypes = new();
|
|
|
|
|
|
2026-07-24 17:35:34 -03:00
|
|
|
public static IServiceCollection AddBusinessServices(this IServiceCollection services, IConfiguration configuration)
|
2026-05-14 11:00:12 -05:00
|
|
|
{
|
2026-07-24 17:35:34 -03:00
|
|
|
services.Configure<FrontendOptions>(configuration);
|
|
|
|
|
services.Configure<JwtOptions>(configuration.GetSection(JwtOptions.SectionName));
|
|
|
|
|
services.Configure<ApprovalsOptions>(configuration.GetSection(ApprovalsOptions.SectionName));
|
|
|
|
|
services.Configure<VendorPortalOptions>(configuration.GetSection(VendorPortalOptions.SectionName));
|
|
|
|
|
services.Configure<VendorDocumentsOptions>(configuration.GetSection(VendorDocumentsOptions.SectionName));
|
|
|
|
|
|
2026-05-14 11:00:12 -05:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|