|
@@ -1,4 +1,5 @@
|
|
|
-using System.Collections;
|
|
|
+using System;
|
|
|
+using System.Collections;
|
|
|
using System.ComponentModel;
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
using System.Diagnostics;
|
|
@@ -9,7 +10,9 @@ using System.Text.Encodings.Web;
|
|
|
using System.Text.Json;
|
|
|
using System.Text.RegularExpressions;
|
|
|
using System.Text.Unicode;
|
|
|
+using Hotline.Share.Tools;
|
|
|
using Hotline.Users;
|
|
|
+using Microsoft.AspNetCore.Builder;
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
using Serilog;
|
|
@@ -18,6 +21,7 @@ using XF.Domain.Entities;
|
|
|
using XF.Domain.Extensions;
|
|
|
using XF.Domain.Options;
|
|
|
using XF.Domain.Repository;
|
|
|
+using XF.Domain.Repository.Events;
|
|
|
using XF.Utility.SequentialId;
|
|
|
|
|
|
namespace Hotline.Repository.SqlSugar.Extensions
|
|
@@ -26,6 +30,7 @@ namespace Hotline.Repository.SqlSugar.Extensions
|
|
|
{
|
|
|
public static void AddSqlSugar(this IServiceCollection services, IConfiguration configuration, string dbName = "Hotline")
|
|
|
{
|
|
|
+ services.AddScoped<DatabaseEventDispatcher>();
|
|
|
//多租户 new SqlSugarScope(List<ConnectionConfig>,db=>{});
|
|
|
|
|
|
SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig()
|
|
@@ -115,7 +120,10 @@ namespace Hotline.Repository.SqlSugar.Extensions
|
|
|
PgSqlIsAutoToLowerCodeFirst = false, // 建表建驼峰表。5.1.3.30
|
|
|
}
|
|
|
},
|
|
|
- SetDbAop
|
|
|
+ db =>
|
|
|
+ {
|
|
|
+ SetDbAop(db, services);
|
|
|
+ }
|
|
|
);
|
|
|
|
|
|
ISugarUnitOfWork<HotlineDbContext> context = new SugarUnitOfWork<HotlineDbContext>(sqlSugar);
|
|
@@ -204,7 +212,7 @@ namespace Hotline.Repository.SqlSugar.Extensions
|
|
|
|
|
|
#region private
|
|
|
|
|
|
- private static void SetDbAop(SqlSugarClient db)
|
|
|
+ private static void SetDbAop(SqlSugarClient db, IServiceCollection services)
|
|
|
{
|
|
|
/***写AOP等方法***/
|
|
|
db.Aop.OnLogExecuting = (sql, pars) =>
|
|
@@ -262,13 +270,15 @@ namespace Hotline.Repository.SqlSugar.Extensions
|
|
|
{
|
|
|
if (entityInfo.EntityColumnInfo.IsPrimarykey && entityInfo.OperationType == DataFilterType.UpdateByObject)
|
|
|
{
|
|
|
- var entityName = entityInfo.EntityName;
|
|
|
- Console.WriteLine(entityName);
|
|
|
+ services.BuildServiceProvider()
|
|
|
+ .GetService<DatabaseEventDispatcher>()?
|
|
|
+ .Dispatch(entityInfo.EntityValue, entityInfo.OperationType);
|
|
|
}
|
|
|
if (entityInfo.EntityColumnInfo.IsPrimarykey && entityInfo.OperationType == DataFilterType.InsertByObject)
|
|
|
{
|
|
|
- var entityName = entityInfo.EntityName;
|
|
|
- Console.WriteLine(entityName);
|
|
|
+ services.BuildServiceProvider()
|
|
|
+ .GetService<DatabaseEventDispatcher>()?
|
|
|
+ .Dispatch(entityInfo.EntityValue, entityInfo.OperationType);
|
|
|
}
|
|
|
};
|
|
|
|