This commit is contained in:
SunCheng
2026-02-10 17:49:19 +08:00
parent 3e18283e52
commit d052ae5197
104 changed files with 10369 additions and 3000 deletions

View File

@@ -0,0 +1,36 @@
namespace Application.Extensions;
/// <summary>
/// Application层服务注册扩展
/// </summary>
public static class ServiceCollectionExtensions
{
/// <summary>
/// 注册所有Application层服务
/// </summary>
public static IServiceCollection AddApplicationServices(this IServiceCollection services)
{
// 获取Application层程序集
var assembly = typeof(ServiceCollectionExtensions).Assembly;
// 自动注册所有以"Application"结尾的类
// 匹配接口规则: IXxxApplication -> XxxApplication
var applicationTypes = assembly.GetTypes()
.Where(t => t.IsClass && !t.IsAbstract && t.Name.EndsWith("Application"))
.ToList();
foreach (var implementationType in applicationTypes)
{
// 查找对应的接口 IXxxApplication
var interfaceType = implementationType.GetInterfaces()
.FirstOrDefault(i => i.Name == $"I{implementationType.Name}");
if (interfaceType != null)
{
services.AddScoped(interfaceType, implementationType);
}
}
return services;
}
}