mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
- 增加 Aop Before/After States 共享状态;
This commit is contained in:
parent
423fabd7c8
commit
ef6665ee29
@ -125,6 +125,42 @@ namespace base_entity
|
|||||||
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
|
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
//fsql.Aop.CommandBefore += (s, e) =>
|
||||||
|
//{
|
||||||
|
// e.States["xxx"] = 111;
|
||||||
|
//};
|
||||||
|
//fsql.Aop.CommandAfter += (s, e) =>
|
||||||
|
//{
|
||||||
|
// var xxx = e.States["xxx"];
|
||||||
|
//};
|
||||||
|
|
||||||
|
//fsql.Aop.TraceBefore += (s, e) =>
|
||||||
|
//{
|
||||||
|
// e.States["xxx"] = 222;
|
||||||
|
//};
|
||||||
|
//fsql.Aop.TraceAfter += (s, e) =>
|
||||||
|
//{
|
||||||
|
// var xxx = e.States["xxx"];
|
||||||
|
//};
|
||||||
|
|
||||||
|
//fsql.Aop.SyncStructureBefore += (s, e) =>
|
||||||
|
//{
|
||||||
|
// e.States["xxx"] = 333;
|
||||||
|
//};
|
||||||
|
//fsql.Aop.SyncStructureAfter += (s, e) =>
|
||||||
|
//{
|
||||||
|
// var xxx = e.States["xxx"];
|
||||||
|
//};
|
||||||
|
|
||||||
|
//fsql.Aop.CurdBefore += (s, e) =>
|
||||||
|
//{
|
||||||
|
// e.States["xxx"] = 444;
|
||||||
|
//};
|
||||||
|
//fsql.Aop.CurdAfter += (s, e) =>
|
||||||
|
//{
|
||||||
|
// var xxx = e.States["xxx"];
|
||||||
|
//};
|
||||||
|
|
||||||
fsql.Insert(new tttorder("xx1", 1, 10)).ExecuteAffrows();
|
fsql.Insert(new tttorder("xx1", 1, 10)).ExecuteAffrows();
|
||||||
fsql.Insert(new tttorder("xx2", 2, 20)).ExecuteAffrows();
|
fsql.Insert(new tttorder("xx2", 2, 20)).ExecuteAffrows();
|
||||||
|
|
||||||
|
@ -512,14 +512,5 @@
|
|||||||
<param name="that"></param>
|
<param name="that"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
|
||||||
<summary>
|
|
||||||
批量注入 Repository,可以参考代码自行调整
|
|
||||||
</summary>
|
|
||||||
<param name="services"></param>
|
|
||||||
<param name="globalDataFilter"></param>
|
|
||||||
<param name="assemblies"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
</members>
|
</members>
|
||||||
</doc>
|
</doc>
|
||||||
|
@ -3458,6 +3458,11 @@
|
|||||||
参数化命令
|
参数化命令
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="P:FreeSql.Aop.CurdBeforeEventArgs.States">
|
||||||
|
<summary>
|
||||||
|
状态数据,可与 CurdAfter 共享
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="P:FreeSql.Aop.CurdAfterEventArgs.Exception">
|
<member name="P:FreeSql.Aop.CurdAfterEventArgs.Exception">
|
||||||
<summary>
|
<summary>
|
||||||
发生的错误
|
发生的错误
|
||||||
@ -3488,6 +3493,11 @@
|
|||||||
实体类型
|
实体类型
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="P:FreeSql.Aop.SyncStructureBeforeEventArgs.States">
|
||||||
|
<summary>
|
||||||
|
状态数据,可与 SyncStructureAfter 共享
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="P:FreeSql.Aop.SyncStructureAfterEventArgs.Sql">
|
<member name="P:FreeSql.Aop.SyncStructureAfterEventArgs.Sql">
|
||||||
<summary>
|
<summary>
|
||||||
执行的 SQL
|
执行的 SQL
|
||||||
@ -3548,6 +3558,11 @@
|
|||||||
标识符,可将 CommandBefore 与 CommandAfter 进行匹配
|
标识符,可将 CommandBefore 与 CommandAfter 进行匹配
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="P:FreeSql.Aop.CommandBeforeEventArgs.States">
|
||||||
|
<summary>
|
||||||
|
状态数据,可与 CommandAfter 共享
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="P:FreeSql.Aop.CommandAfterEventArgs.Exception">
|
<member name="P:FreeSql.Aop.CommandAfterEventArgs.Exception">
|
||||||
<summary>
|
<summary>
|
||||||
发生的错误
|
发生的错误
|
||||||
@ -3573,6 +3588,11 @@
|
|||||||
标识符,可将 TraceBeforeEventArgs 与 TraceAfterEventArgs 进行匹配
|
标识符,可将 TraceBeforeEventArgs 与 TraceAfterEventArgs 进行匹配
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="P:FreeSql.Aop.TraceBeforeEventArgs.States">
|
||||||
|
<summary>
|
||||||
|
状态数据,可与 TraceAfter 共享
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="P:FreeSql.Aop.TraceAfterEventArgs.Remark">
|
<member name="P:FreeSql.Aop.TraceAfterEventArgs.Remark">
|
||||||
<summary>
|
<summary>
|
||||||
备注
|
备注
|
||||||
|
@ -165,11 +165,11 @@ namespace FreeSql.Aop
|
|||||||
public class CurdBeforeEventArgs : EventArgs
|
public class CurdBeforeEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
public CurdBeforeEventArgs(Type entityType, TableInfo table, CurdType curdType, string sql, DbParameter[] dbParms) :
|
public CurdBeforeEventArgs(Type entityType, TableInfo table, CurdType curdType, string sql, DbParameter[] dbParms) :
|
||||||
this(Guid.NewGuid(), new Stopwatch(), entityType, table, curdType, sql, dbParms)
|
this(Guid.NewGuid(), new Stopwatch(), entityType, table, curdType, sql, dbParms, new Dictionary<string, object>())
|
||||||
{
|
{
|
||||||
this.Stopwatch.Start();
|
this.Stopwatch.Start();
|
||||||
}
|
}
|
||||||
protected CurdBeforeEventArgs(Guid identifier, Stopwatch stopwatch, Type entityType, TableInfo table, CurdType curdType, string sql, DbParameter[] dbParms)
|
protected CurdBeforeEventArgs(Guid identifier, Stopwatch stopwatch, Type entityType, TableInfo table, CurdType curdType, string sql, DbParameter[] dbParms, Dictionary<string, object> states)
|
||||||
{
|
{
|
||||||
this.Identifier = identifier;
|
this.Identifier = identifier;
|
||||||
this.Stopwatch = stopwatch;
|
this.Stopwatch = stopwatch;
|
||||||
@ -178,6 +178,7 @@ namespace FreeSql.Aop
|
|||||||
this.CurdType = curdType;
|
this.CurdType = curdType;
|
||||||
this.Sql = sql;
|
this.Sql = sql;
|
||||||
this.DbParms = dbParms;
|
this.DbParms = dbParms;
|
||||||
|
this.States = states;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -206,12 +207,16 @@ namespace FreeSql.Aop
|
|||||||
/// 参数化命令
|
/// 参数化命令
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DbParameter[] DbParms { get; }
|
public DbParameter[] DbParms { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// 状态数据,可与 CurdAfter 共享
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<string, object> States { get; protected set; }
|
||||||
}
|
}
|
||||||
public enum CurdType { Select, Delete, Update, Insert, InsertOrUpdate }
|
public enum CurdType { Select, Delete, Update, Insert, InsertOrUpdate }
|
||||||
public class CurdAfterEventArgs : CurdBeforeEventArgs
|
public class CurdAfterEventArgs : CurdBeforeEventArgs
|
||||||
{
|
{
|
||||||
public CurdAfterEventArgs(CurdBeforeEventArgs before, Exception exception, object executeResult) :
|
public CurdAfterEventArgs(CurdBeforeEventArgs before, Exception exception, object executeResult) :
|
||||||
base(before.Identifier, before.StopwatchInternal, before.EntityType, before.Table, before.CurdType, before.Sql, before.DbParms)
|
base(before.Identifier, before.StopwatchInternal, before.EntityType, before.Table, before.CurdType, before.Sql, before.DbParms, before.States)
|
||||||
{
|
{
|
||||||
this.Exception = exception;
|
this.Exception = exception;
|
||||||
this.ExecuteResult = executeResult;
|
this.ExecuteResult = executeResult;
|
||||||
@ -241,15 +246,16 @@ namespace FreeSql.Aop
|
|||||||
public class SyncStructureBeforeEventArgs : EventArgs
|
public class SyncStructureBeforeEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
public SyncStructureBeforeEventArgs(Type[] entityTypes) :
|
public SyncStructureBeforeEventArgs(Type[] entityTypes) :
|
||||||
this(Guid.NewGuid(), new Stopwatch(), entityTypes)
|
this(Guid.NewGuid(), new Stopwatch(), entityTypes, new Dictionary<string, object>())
|
||||||
{
|
{
|
||||||
this.Stopwatch.Start();
|
this.Stopwatch.Start();
|
||||||
}
|
}
|
||||||
protected SyncStructureBeforeEventArgs(Guid identifier, Stopwatch stopwatch, Type[] entityTypes)
|
protected SyncStructureBeforeEventArgs(Guid identifier, Stopwatch stopwatch, Type[] entityTypes, Dictionary<string, object> states)
|
||||||
{
|
{
|
||||||
this.Identifier = identifier;
|
this.Identifier = identifier;
|
||||||
this.Stopwatch = stopwatch;
|
this.Stopwatch = stopwatch;
|
||||||
this.EntityTypes = entityTypes;
|
this.EntityTypes = entityTypes;
|
||||||
|
this.States = states;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -262,11 +268,15 @@ namespace FreeSql.Aop
|
|||||||
/// 实体类型
|
/// 实体类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Type[] EntityTypes { get; }
|
public Type[] EntityTypes { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// 状态数据,可与 SyncStructureAfter 共享
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<string, object> States { get; protected set; }
|
||||||
}
|
}
|
||||||
public class SyncStructureAfterEventArgs : SyncStructureBeforeEventArgs
|
public class SyncStructureAfterEventArgs : SyncStructureBeforeEventArgs
|
||||||
{
|
{
|
||||||
public SyncStructureAfterEventArgs(SyncStructureBeforeEventArgs before, string sql, Exception exception) :
|
public SyncStructureAfterEventArgs(SyncStructureBeforeEventArgs before, string sql, Exception exception) :
|
||||||
base(before.Identifier, before.StopwatchInternal, before.EntityTypes)
|
base(before.Identifier, before.StopwatchInternal, before.EntityTypes, before.States)
|
||||||
{
|
{
|
||||||
this.Sql = sql;
|
this.Sql = sql;
|
||||||
this.Exception = exception;
|
this.Exception = exception;
|
||||||
@ -381,15 +391,16 @@ namespace FreeSql.Aop
|
|||||||
public class CommandBeforeEventArgs : EventArgs
|
public class CommandBeforeEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
public CommandBeforeEventArgs(DbCommand command) :
|
public CommandBeforeEventArgs(DbCommand command) :
|
||||||
this(Guid.NewGuid(), new Stopwatch(), command)
|
this(Guid.NewGuid(), new Stopwatch(), command, new Dictionary<string, object>())
|
||||||
{
|
{
|
||||||
this.Stopwatch.Start();
|
this.Stopwatch.Start();
|
||||||
}
|
}
|
||||||
protected CommandBeforeEventArgs(Guid identifier, Stopwatch stopwatch, DbCommand command)
|
protected CommandBeforeEventArgs(Guid identifier, Stopwatch stopwatch, DbCommand command, Dictionary<string, object> states)
|
||||||
{
|
{
|
||||||
this.Identifier = identifier;
|
this.Identifier = identifier;
|
||||||
this.Stopwatch = stopwatch;
|
this.Stopwatch = stopwatch;
|
||||||
this.Command = command;
|
this.Command = command;
|
||||||
|
this.States = states;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -399,11 +410,15 @@ namespace FreeSql.Aop
|
|||||||
protected Stopwatch Stopwatch { get; }
|
protected Stopwatch Stopwatch { get; }
|
||||||
internal Stopwatch StopwatchInternal => Stopwatch;
|
internal Stopwatch StopwatchInternal => Stopwatch;
|
||||||
public DbCommand Command { get; }
|
public DbCommand Command { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// 状态数据,可与 CommandAfter 共享
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<string, object> States { get; protected set; }
|
||||||
}
|
}
|
||||||
public class CommandAfterEventArgs : CommandBeforeEventArgs
|
public class CommandAfterEventArgs : CommandBeforeEventArgs
|
||||||
{
|
{
|
||||||
public CommandAfterEventArgs(CommandBeforeEventArgs before, Exception exception, string log) :
|
public CommandAfterEventArgs(CommandBeforeEventArgs before, Exception exception, string log) :
|
||||||
base(before.Identifier, before.StopwatchInternal, before.Command)
|
base(before.Identifier, before.StopwatchInternal, before.Command, before.States)
|
||||||
{
|
{
|
||||||
this.Exception = exception;
|
this.Exception = exception;
|
||||||
this.Log = log;
|
this.Log = log;
|
||||||
@ -433,16 +448,17 @@ namespace FreeSql.Aop
|
|||||||
public class TraceBeforeEventArgs : EventArgs
|
public class TraceBeforeEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
public TraceBeforeEventArgs(string operation, object value) :
|
public TraceBeforeEventArgs(string operation, object value) :
|
||||||
this(Guid.NewGuid(), new Stopwatch(), operation, value)
|
this(Guid.NewGuid(), new Stopwatch(), operation, value, new Dictionary<string, object>())
|
||||||
{
|
{
|
||||||
this.Stopwatch.Start();
|
this.Stopwatch.Start();
|
||||||
}
|
}
|
||||||
protected TraceBeforeEventArgs(Guid identifier, Stopwatch stopwatch, string operation, object value)
|
protected TraceBeforeEventArgs(Guid identifier, Stopwatch stopwatch, string operation, object value, Dictionary<string, object> states)
|
||||||
{
|
{
|
||||||
this.Identifier = identifier;
|
this.Identifier = identifier;
|
||||||
this.Stopwatch = stopwatch;
|
this.Stopwatch = stopwatch;
|
||||||
this.Operation = operation;
|
this.Operation = operation;
|
||||||
this.Value = value;
|
this.Value = value;
|
||||||
|
this.States = states;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -453,11 +469,15 @@ namespace FreeSql.Aop
|
|||||||
internal Stopwatch StopwatchInternal => Stopwatch;
|
internal Stopwatch StopwatchInternal => Stopwatch;
|
||||||
public string Operation { get; }
|
public string Operation { get; }
|
||||||
public object Value { get; }
|
public object Value { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// 状态数据,可与 TraceAfter 共享
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<string, object> States { get; protected set; }
|
||||||
}
|
}
|
||||||
public class TraceAfterEventArgs : TraceBeforeEventArgs
|
public class TraceAfterEventArgs : TraceBeforeEventArgs
|
||||||
{
|
{
|
||||||
public TraceAfterEventArgs(TraceBeforeEventArgs before, string remark, Exception exception) :
|
public TraceAfterEventArgs(TraceBeforeEventArgs before, string remark, Exception exception) :
|
||||||
base(before.Identifier, before.StopwatchInternal, before.Operation, before.Value)
|
base(before.Identifier, before.StopwatchInternal, before.Operation, before.Value, before.States)
|
||||||
{
|
{
|
||||||
this.Remark = remark;
|
this.Remark = remark;
|
||||||
this.Exception = exception;
|
this.Exception = exception;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user