mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 21:13:12 +00:00
35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using System.Reflection;
|
|
|
|
namespace SeaHaven.DataServices.DependencyInjection
|
|
{
|
|
public static class DataServicesModule
|
|
{
|
|
private static readonly List<Type> ExcludedTypes = new();
|
|
|
|
public static IServiceCollection AddDataServices(this IServiceCollection services)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
|
|
return services;
|
|
}
|
|
}
|
|
}
|