Add Module interface. use ConfigureModule method to build Module
This commit is contained in:
parent
dad8608d63
commit
59e8845568
|
@ -0,0 +1,10 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace LFlow.Base.Interfaces;
|
||||||
|
/// <summary>
|
||||||
|
/// 模块接口
|
||||||
|
/// </summary>
|
||||||
|
public interface IModule
|
||||||
|
{
|
||||||
|
void ConfigureModule(IServiceCollection services);
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue