Add Module interface. use ConfigureModule method to build Module

This commit is contained in:
lihanbo 2024-10-16 11:17:16 +08:00
parent dad8608d63
commit 59e8845568
2 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,10 @@
using System;
namespace LFlow.Base.Interfaces;
/// <summary>
/// 模块接口
/// </summary>
public interface IModule
{
void ConfigureModule(IServiceCollection services);
}

View File

@ -0,0 +1,67 @@
using System;
using LFlow.Base.Interfaces;
namespace LFlow.Base.Utils;
public static class RegisterModule
{
public static void RegisterAllModule(this List<Type> types, IServiceCollection services)
{
foreach (var type in types)
{
if (type.IsAbstract || !type.IsClass)
{
continue;
}
var interfaces = type.GetInterfaces();
foreach (var inter in interfaces)
{
if (inter.Name.Equals("IDataModel"))
{
services.AddScoped(inter, type);
}
}
}
}
public static void RegisterAllService(this List<Type> types, IServiceCollection services)
{
foreach (var type in types)
{
if (type.IsAbstract || !type.IsClass)
{
continue;
}
var interfaces = type.GetInterfaces();
foreach (var inter in interfaces)
{
if (inter.Name.Contains(type.Name) && inter.Name.StartsWith('I') && inter.Name.Contains("Service"))
{
//注册服务
services.AddScoped(inter, type);
}
}
}
}
public static void RegisterAllRepo(this List<Type> types, IServiceCollection services)
{
foreach (var type in types)
{
if (type.IsAbstract || !type.IsClass)
{
continue;
}
var interfaces = type.GetInterfaces();
foreach (var inter in interfaces)
{
if (inter.Name.Contains("IRepo"))
{
//注册数据仓库
services.AddScoped(inter, type);
}
}
}
}
}