From 59e8845568e44a3ef5a17081f1c5e4f52c483ac4 Mon Sep 17 00:00:00 2001 From: lihanbo Date: Wed, 16 Oct 2024 11:17:16 +0800 Subject: [PATCH] Add Module interface. use ConfigureModule method to build Module --- LFlow/Interfaces/IModule.cs | 10 ++++++ LFlow/Utils/RegisterModule.cs | 67 +++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 LFlow/Interfaces/IModule.cs create mode 100644 LFlow/Utils/RegisterModule.cs 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); + } + } + } + } +}