diff --git a/LFlow.Base/App.cs b/LFlow.Base/App.cs
index 32d6449..18873ac 100644
--- a/LFlow.Base/App.cs
+++ b/LFlow.Base/App.cs
@@ -6,12 +6,25 @@ namespace LFlow.Base;
///
public class App
{
+ ///
+ /// 服务集合
+ ///
internal static IServiceCollection? services;
+ ///
+ /// 服务提供者
+ ///
private static IServiceProvider? ServiceProvider => services?.BuildServiceProvider();
+ ///
+ /// 获取服务
+ ///
+ ///
+ ///
public static T? GetService()
{
return ServiceProvider!.GetService();
}
-
+ ///
+ /// 子服务程序集
+ ///
public static List SubServiceAssembly = [];
}
diff --git a/LFlow.Base/Base.xml b/LFlow.Base/Base.xml
index aa64fcc..96e4fc5 100644
--- a/LFlow.Base/Base.xml
+++ b/LFlow.Base/Base.xml
@@ -9,6 +9,28 @@
程序对象
+
+
+ 服务集合
+
+
+
+
+ 服务提供者
+
+
+
+
+ 获取服务
+
+
+
+
+
+
+ 子服务程序集
+
+
默认的增删改查仓储
@@ -16,6 +38,17 @@
+
+
+ 数据库连接客户端
+
+
+
+
+ 构造函数
+
+
+
根据ID删除对象
@@ -68,6 +101,45 @@
Route("api/[controller]/[action]") ApiController
+
+
+ 成功返回
+
+
+
+
+
+
+
+ 成功返回(分页)
+
+
+
+
+
+
+
+
+
+
+ 失败返回
+
+
+
+
+
+
+
+
+
+ 失败返回(分页)
+
+
+
+
+
+
+
控制器接口
@@ -93,6 +165,12 @@
模块接口
+
+
+ 配置模块
+
+
+
通用的仓库对象接口
@@ -119,6 +197,7 @@
保存与更新
+
@@ -127,6 +206,7 @@
+
@@ -146,14 +226,35 @@
服务接口
+
+
+
+
+
-
+
+
+
+ 入口
+
+
+
+
+
+ 配置SqlSugar
+
+
从子文件夹中加载DLL
+
+
+ 配置DLL加载器
+
+
控制器模型约定
@@ -171,6 +272,88 @@
+
+
+ 数据
+
+
+
+
+ 构造函数
+
+
+
+
+ 构造函数
+
+
+
+
+
+
+
+
+ 是否成功
+
+
+
+
+ 消息
+
+
+
+
+ 状态码
+
+
+
+
+ 成功返回
+
+
+
+
+
+
+
+
+ 失败返回
+
+
+
+
+
+
+
+ CodeFirst
+
+
+
+
+ 类型集合
+
+
+
+
+ 添加类型
+
+
+
+
+
+ 初始化表
+
+
+
+
+ 初始化数据库种子
+
+
+
+
+ 映射器
+
+
将一个对象映射到另一个对象
@@ -179,6 +362,19 @@
+
+
+ 将一个数据模型映射到另一个对象
+
+
+
+
+
+
+
+ 对象转换为where条件
+
+
将IModel对象转换为where条件
@@ -192,6 +388,68 @@
+
+
+ 数据
+
+
+
+
+ 总行数
+
+
+
+
+ 当前页
+
+
+
+
+ 每页行数
+
+
+
+
+ 构造函数
+
+
+
+
+ 构造函数
+
+
+
+
+
+
+
+
+
+
+
+ 成功返回
+
+
+
+
+
+
+
+
+
+
+
+ 失败返回
+
+
+
+
+
+
+
+ 注册模块
+
+
注册所有模型
diff --git a/LFlow.Base/Default/DefaultCurdRepo.cs b/LFlow.Base/Default/DefaultCurdRepo.cs
index 1e4b77b..24855f7 100644
--- a/LFlow.Base/Default/DefaultCurdRepo.cs
+++ b/LFlow.Base/Default/DefaultCurdRepo.cs
@@ -10,7 +10,14 @@ namespace LFlow.Base.Default;
///
public abstract class DefaultCurdRepo : IRepo where T : class, IDataModel, new()
{
+ ///
+ /// 数据库连接客户端
+ ///
private readonly ISqlSugarClient _client;
+ ///
+ /// 构造函数
+ ///
+ ///
public DefaultCurdRepo(ISqlSugarClient client)
{
_client = client;
diff --git a/LFlow.Base/Interfaces/BaseController.cs b/LFlow.Base/Interfaces/BaseController.cs
index 8b8ae54..4857d80 100644
--- a/LFlow.Base/Interfaces/BaseController.cs
+++ b/LFlow.Base/Interfaces/BaseController.cs
@@ -11,19 +11,49 @@ namespace LFlow.Base.Interfaces;
[ApiController]
public abstract class BaseController : ControllerBase, IController
{
+ ///
+ /// 成功返回
+ ///
+ ///
+ ///
+ ///
protected virtual ApiResult Success(T? data) where T : class, new()
{
return ApiResult.SuccessResult(data);
}
+ ///
+ /// 成功返回(分页)
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
protected virtual PagedApiResult Success(T? data, int totalCount, int pageIndex, int pageSize) where T : class, new()
{
return PagedApiResult.SuccessResult(data, totalCount, pageIndex, pageSize);
}
-
+ ///
+ /// 失败返回
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
protected virtual ApiResult Fail(T? data, string errorMsg, int errCode) where T : class, new()
{
return ApiResult.FailResult(errorMsg, errCode);
}
+ ///
+ /// 失败返回(分页)
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
protected virtual PagedApiResult? PagedFail(T? data, string errorMsg, int errCode) where T : class, new()
{
return PagedApiResult.FailResult(errorMsg, errCode);
diff --git a/LFlow.Base/Interfaces/IModule.cs b/LFlow.Base/Interfaces/IModule.cs
index da70537..85b406f 100644
--- a/LFlow.Base/Interfaces/IModule.cs
+++ b/LFlow.Base/Interfaces/IModule.cs
@@ -6,5 +6,9 @@ namespace LFlow.Base.Interfaces;
///
public interface IModule
{
+ ///
+ /// 配置模块
+ ///
+ ///
void ConfigureModule(IServiceCollection services);
}
diff --git a/LFlow.Base/Interfaces/IRepo.cs b/LFlow.Base/Interfaces/IRepo.cs
index 681d11b..a311a03 100644
--- a/LFlow.Base/Interfaces/IRepo.cs
+++ b/LFlow.Base/Interfaces/IRepo.cs
@@ -23,6 +23,7 @@ public interface IRepo where T : IDataModel
/// 保存与更新
///
///
+ ///
///
T SaveOrUpdate(T entity, bool isUpdate);
///
@@ -30,6 +31,7 @@ public interface IRepo where T : IDataModel
///
///
///
+ ///
///
List GetAll(int pageIndex, int pageSize, ref int pageTotal);
diff --git a/LFlow.Base/Interfaces/IService.cs b/LFlow.Base/Interfaces/IService.cs
index ec87f50..a518f1f 100644
--- a/LFlow.Base/Interfaces/IService.cs
+++ b/LFlow.Base/Interfaces/IService.cs
@@ -1,8 +1,7 @@
namespace LFlow.Base.Interfaces;
///
-/// ӿ
-///
-///
+/// 服务接口
+///
public interface IService// where T : class, IModel, new()
{
diff --git a/LFlow.Base/Program.cs b/LFlow.Base/Program.cs
index 0b0c195..39b1225 100644
--- a/LFlow.Base/Program.cs
+++ b/LFlow.Base/Program.cs
@@ -11,9 +11,15 @@ using SqlSugar;
using System.Reflection;
namespace LFlow.Base;
+///
+///
+///
public static class Program
{
-
+ ///
+ /// 入口
+ ///
+ ///
public static void Main(string[] args)
{
@@ -47,8 +53,10 @@ public static class Program
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddHttpContextAccessor();
+ builder.Services.AddResponseCompression();
Log.Logger.Information("ConfigureSqlSugar");
+
builder.Services.ConfigureSqlSugar();
builder.Services.AddControllers(c =>
@@ -87,6 +95,8 @@ public static class Program
});
});
});
+
+
// 配置跨域策略
builder.Services.AddCors(options =>
{
@@ -149,7 +159,7 @@ public static class Program
}
// 在启动后调用Sqlsugar进行CodeFirst
// 挂载启动后事件
- app.Services.GetRequiredService().ApplicationStarted.Register(async () =>
+ app.Services.GetRequiredService().ApplicationStarted.Register(() =>
{
Log.Logger.Information("ApplicationStarted");
CodeFirst.InitTable();
@@ -170,6 +180,10 @@ public static class Program
app.Run();
}
+ ///
+ /// 配置SqlSugar
+ ///
+ ///
public static void ConfigureSqlSugar(this IServiceCollection services)
{
services.AddSingleton(s =>
@@ -260,6 +274,9 @@ public static class Program
}
+ ///
+ /// 配置DLL加载器
+ ///
public static void ConfigDllLoader()
{
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
diff --git a/LFlow.Base/Utils/ApiResult.cs b/LFlow.Base/Utils/ApiResult.cs
index 9fb7171..ae7a925 100644
--- a/LFlow.Base/Utils/ApiResult.cs
+++ b/LFlow.Base/Utils/ApiResult.cs
@@ -7,15 +7,26 @@
[Serializable]
public class ApiResult where T : class, new()
{
+ ///
+ /// 数据
+ ///
public T? Data
{
get; set;
}
-
+ ///
+ /// 构造函数
+ ///
public ApiResult()
{
}
-
+ ///
+ /// 构造函数
+ ///
+ ///
+ ///
+ ///
+ ///
public ApiResult(bool success, string message, int code, T? data)
{
Success = success;
@@ -23,26 +34,44 @@ public class ApiResult where T : class, new()
Code = code;
Data = data;
}
-
+ ///
+ /// 是否成功
+ ///
public bool Success
{
get; set;
}
-
+ ///
+ /// 消息
+ ///
public string? Message
{
get; set;
}
-
+ ///
+ /// 状态码
+ ///
public int? Code
{
get; set;
}
-
+ ///
+ /// 成功返回
+ ///
+ ///
+ ///
+ ///
+ ///
public static ApiResult SuccessResult(T? data, string message = "操作成功", int code = 200)
{
return new ApiResult(true, message, code, data);
}
+ ///
+ /// 失败返回
+ ///
+ ///
+ ///
+ ///
public static ApiResult FailResult(string message = "操作失败", int code = 500)
{
return new ApiResult(false, message, code, default);
diff --git a/LFlow.Base/Utils/CodeFirst.cs b/LFlow.Base/Utils/CodeFirst.cs
index 25cb83d..65dfe03 100644
--- a/LFlow.Base/Utils/CodeFirst.cs
+++ b/LFlow.Base/Utils/CodeFirst.cs
@@ -2,15 +2,27 @@ using SqlSugar;
using System.Collections.Concurrent;
namespace LFlow.Base.Utils;
-
+///
+/// CodeFirst
+///
public static class CodeFirst
{
- // 线程安全的类型列表
- private static readonly ConcurrentBag _types = new();
+
+ ///
+ /// 类型集合
+ ///
+ private static readonly ConcurrentBag _types = [];
+ ///
+ /// 添加类型
+ ///
+ ///
public static void AddType(Type type)
{
_types.Add(type);
}
+ ///
+ /// 初始化表
+ ///
internal static void InitTable()
{
var logger = App.GetService()!;
@@ -22,6 +34,9 @@ public static class CodeFirst
}
}
+ ///
+ /// 初始化数据库种子
+ ///
internal static void InitDBSeed()
{
//TODO: Seed data
diff --git a/LFlow.Base/Utils/Mapper.cs b/LFlow.Base/Utils/Mapper.cs
index d5ba2b0..1516847 100644
--- a/LFlow.Base/Utils/Mapper.cs
+++ b/LFlow.Base/Utils/Mapper.cs
@@ -2,7 +2,9 @@ using LFlow.Base.Interfaces;
using Mapster;
namespace LFlow.Base.Utils;
-
+///
+/// 映射器
+///
public static class Mapper
{
///
@@ -19,6 +21,12 @@ public static class Mapper
}
return source.Adapt();
}
+ ///
+ /// 将一个数据模型映射到另一个对象
+ ///
+ ///
+ ///
+ ///
public static T? MapTo(this IDataModel model)
{
if (model == null)
diff --git a/LFlow.Base/Utils/ObjectToWhereExp.cs b/LFlow.Base/Utils/ObjectToWhereExp.cs
index f4ef5c7..74dde9e 100644
--- a/LFlow.Base/Utils/ObjectToWhereExp.cs
+++ b/LFlow.Base/Utils/ObjectToWhereExp.cs
@@ -1,7 +1,9 @@
using LFlow.Base.Interfaces;
namespace LFlow.Base.Utils;
-
+///
+/// 对象转换为where条件
+///
public static class ObjectToWhereExp
{
///
diff --git a/LFlow.Base/Utils/PagedApiResult.cs b/LFlow.Base/Utils/PagedApiResult.cs
index 12a8999..7da995a 100644
--- a/LFlow.Base/Utils/PagedApiResult.cs
+++ b/LFlow.Base/Utils/PagedApiResult.cs
@@ -7,29 +7,51 @@
[Serializable]
public class PagedApiResult : ApiResult where T : class, new()
{
+ ///
+ /// 数据
+ ///
public new T? Data
{
get; set;
}
+ ///
+ /// 总行数
+ ///
public int TotalCount
{
get; set;
}
+ ///
+ /// 当前页
+ ///
public int PageIndex
{
get; set;
}
-
+ ///
+ /// 每页行数
+ ///
public int PageSize
{
get; set;
}
-
+ ///
+ /// 构造函数
+ ///
public PagedApiResult()
{
}
-
+ ///
+ /// 构造函数
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
public PagedApiResult(bool success, string message, int code, T? data, int totalCount, int pageIndex, int pageSize)
{
Success = success;
@@ -40,10 +62,26 @@ public class PagedApiResult : ApiResult where T : class, new()
PageIndex = pageIndex;
PageSize = pageSize;
}
+ ///
+ /// 成功返回
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
public static PagedApiResult SuccessResult(T? data, int totalCount, int pageIndex, int pageSize, string message = "操作成功", int code = 200)
{
return new PagedApiResult(true, message, code, data, totalCount, pageIndex, pageSize);
}
+ ///
+ /// 失败返回
+ ///
+ ///
+ ///
+ ///
public static new PagedApiResult? FailResult(string message = "操作失败", int errCode = 500)
{
return new PagedApiResult(false, message, errCode, null, 0, 0, 0);
diff --git a/LFlow.Base/Utils/RegisterModule.cs b/LFlow.Base/Utils/RegisterModule.cs
index 87a9ac1..20d0973 100644
--- a/LFlow.Base/Utils/RegisterModule.cs
+++ b/LFlow.Base/Utils/RegisterModule.cs
@@ -1,5 +1,7 @@
namespace LFlow.Base.Utils;
-
+///
+/// 注册模块
+///
public static class RegisterModule
{
///
diff --git a/LFlow.InternalEventBus/InternalEventBus.cs b/LFlow.InternalEventBus/InternalEventBus.cs
index 6dcf598..3f1f2d2 100644
--- a/LFlow.InternalEventBus/InternalEventBus.cs
+++ b/LFlow.InternalEventBus/InternalEventBus.cs
@@ -59,7 +59,7 @@ namespace LFlow.InternalEventBus
///
public static async Task PublishAsync(string eventName, object data)
{
- Task.Factory.StartNew(() => Publish(eventName, data));
+ await Task.Factory.StartNew(() => Publish(eventName, data));
}
diff --git a/LFlow.Middleware/Middlewares/LoggingMiddleware.cs b/LFlow.Middleware/Middlewares/LoggingMiddleware.cs
index 71dda0c..b8a795c 100644
--- a/LFlow.Middleware/Middlewares/LoggingMiddleware.cs
+++ b/LFlow.Middleware/Middlewares/LoggingMiddleware.cs
@@ -15,13 +15,34 @@
{
var controllerName = context.GetRouteData()?.Values["controller"]?.ToString();
var actionName = context.GetRouteData()?.Values["action"]?.ToString();
-
- using (_logger?.BeginScope("LoggingMiddleware"))
+ var requestId = context.Request.Headers["X-Request-Id"].ToString();
+ if (string.IsNullOrEmpty(requestId))
{
- _logger?.LogInformation($"Controller: {controllerName} / Action : {actionName}");
- _logger?.LogInformation("Router Data {@routerData}", context.GetRouteData());
- await next();
+ requestId = Guid.NewGuid().ToString();
+ context.Request.Headers.Append("X-Request-Id", requestId);
}
+ using (_logger?.BeginScope(requestId))
+ {
+ _logger?.LogInformation("Request Id: {requestId}", requestId);
+ _logger?.LogInformation("Controller: {controllerName} / Action : {actionName}", controllerName, actionName);
+ // _logger?.LogInformation("Router Data {@routerData}", context.GetRouteData());
+ try
+ {
+ await next();
+ }
+ catch (Exception ex)
+ {
+ _logger?.LogError(ex, "An error occurred while processing the request. Request Id: {requestId}", requestId);
+ //await context.Response.WriteAsync(JsonConvert.SerializeObject(ApiResult