diff --git a/LFlow/Interfaces/IModule.cs b/LFlow/Interfaces/IModule.cs new file mode 100644 index 0000000..da70537 --- /dev/null +++ b/LFlow/Interfaces/IModule.cs @@ -0,0 +1,10 @@ +using System; + +namespace LFlow.Base.Interfaces; +/// +/// 模块接口 +/// +public interface IModule +{ + void ConfigureModule(IServiceCollection services); +} diff --git a/LFlow/Utils/RegisterModule.cs b/LFlow/Utils/RegisterModule.cs new file mode 100644 index 0000000..c95d834 --- /dev/null +++ b/LFlow/Utils/RegisterModule.cs @@ -0,0 +1,67 @@ +using System; +using LFlow.Base.Interfaces; + +namespace LFlow.Base.Utils; + +public static class RegisterModule +{ + public static void RegisterAllModule(this List 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 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 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); + } + } + } + } +}