diff --git a/Examples/base_entity/Program.cs b/Examples/base_entity/Program.cs index bacf2043..9c7fda76 100644 --- a/Examples/base_entity/Program.cs +++ b/Examples/base_entity/Program.cs @@ -125,6 +125,42 @@ namespace base_entity BaseEntity.Initialization(fsql, () => _asyncUow.Value); #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("xx2", 2, 20)).ExecuteAffrows(); diff --git a/FreeSql.DbContext/FreeSql.DbContext.xml b/FreeSql.DbContext/FreeSql.DbContext.xml index 27909b2e..02eb0609 100644 --- a/FreeSql.DbContext/FreeSql.DbContext.xml +++ b/FreeSql.DbContext/FreeSql.DbContext.xml @@ -512,14 +512,5 @@ - - - 批量注入 Repository,可以参考代码自行调整 - - - - - - diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml index 560f7763..fd0aedfe 100644 --- a/FreeSql/FreeSql.xml +++ b/FreeSql/FreeSql.xml @@ -3458,6 +3458,11 @@ 参数化命令 + + + 状态数据,可与 CurdAfter 共享 + + 发生的错误 @@ -3488,6 +3493,11 @@ 实体类型 + + + 状态数据,可与 SyncStructureAfter 共享 + + 执行的 SQL @@ -3548,6 +3558,11 @@ 标识符,可将 CommandBefore 与 CommandAfter 进行匹配 + + + 状态数据,可与 CommandAfter 共享 + + 发生的错误 @@ -3573,6 +3588,11 @@ 标识符,可将 TraceBeforeEventArgs 与 TraceAfterEventArgs 进行匹配 + + + 状态数据,可与 TraceAfter 共享 + + 备注 diff --git a/FreeSql/Interface/IAop.cs b/FreeSql/Interface/IAop.cs index a3913c4d..9de02937 100644 --- a/FreeSql/Interface/IAop.cs +++ b/FreeSql/Interface/IAop.cs @@ -165,11 +165,11 @@ namespace FreeSql.Aop public class CurdBeforeEventArgs : EventArgs { 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()) { 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 states) { this.Identifier = identifier; this.Stopwatch = stopwatch; @@ -178,6 +178,7 @@ namespace FreeSql.Aop this.CurdType = curdType; this.Sql = sql; this.DbParms = dbParms; + this.States = states; } /// @@ -206,12 +207,16 @@ namespace FreeSql.Aop /// 参数化命令 /// public DbParameter[] DbParms { get; } + /// + /// 状态数据,可与 CurdAfter 共享 + /// + public Dictionary States { get; protected set; } } public enum CurdType { Select, Delete, Update, Insert, InsertOrUpdate } public class CurdAfterEventArgs : CurdBeforeEventArgs { 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.ExecuteResult = executeResult; @@ -241,15 +246,16 @@ namespace FreeSql.Aop public class SyncStructureBeforeEventArgs : EventArgs { public SyncStructureBeforeEventArgs(Type[] entityTypes) : - this(Guid.NewGuid(), new Stopwatch(), entityTypes) + this(Guid.NewGuid(), new Stopwatch(), entityTypes, new Dictionary()) { this.Stopwatch.Start(); } - protected SyncStructureBeforeEventArgs(Guid identifier, Stopwatch stopwatch, Type[] entityTypes) + protected SyncStructureBeforeEventArgs(Guid identifier, Stopwatch stopwatch, Type[] entityTypes, Dictionary states) { this.Identifier = identifier; this.Stopwatch = stopwatch; this.EntityTypes = entityTypes; + this.States = states; } /// @@ -262,11 +268,15 @@ namespace FreeSql.Aop /// 实体类型 /// public Type[] EntityTypes { get; } + /// + /// 状态数据,可与 SyncStructureAfter 共享 + /// + public Dictionary States { get; protected set; } } public class SyncStructureAfterEventArgs : SyncStructureBeforeEventArgs { 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.Exception = exception; @@ -381,15 +391,16 @@ namespace FreeSql.Aop public class CommandBeforeEventArgs : EventArgs { public CommandBeforeEventArgs(DbCommand command) : - this(Guid.NewGuid(), new Stopwatch(), command) + this(Guid.NewGuid(), new Stopwatch(), command, new Dictionary()) { this.Stopwatch.Start(); } - protected CommandBeforeEventArgs(Guid identifier, Stopwatch stopwatch, DbCommand command) + protected CommandBeforeEventArgs(Guid identifier, Stopwatch stopwatch, DbCommand command, Dictionary states) { this.Identifier = identifier; this.Stopwatch = stopwatch; this.Command = command; + this.States = states; } /// @@ -399,11 +410,15 @@ namespace FreeSql.Aop protected Stopwatch Stopwatch { get; } internal Stopwatch StopwatchInternal => Stopwatch; public DbCommand Command { get; } + /// + /// 状态数据,可与 CommandAfter 共享 + /// + public Dictionary States { get; protected set; } } public class CommandAfterEventArgs : CommandBeforeEventArgs { 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.Log = log; @@ -433,16 +448,17 @@ namespace FreeSql.Aop public class TraceBeforeEventArgs : EventArgs { public TraceBeforeEventArgs(string operation, object value) : - this(Guid.NewGuid(), new Stopwatch(), operation, value) + this(Guid.NewGuid(), new Stopwatch(), operation, value, new Dictionary()) { this.Stopwatch.Start(); } - protected TraceBeforeEventArgs(Guid identifier, Stopwatch stopwatch, string operation, object value) + protected TraceBeforeEventArgs(Guid identifier, Stopwatch stopwatch, string operation, object value, Dictionary states) { this.Identifier = identifier; this.Stopwatch = stopwatch; this.Operation = operation; this.Value = value; + this.States = states; } /// @@ -453,11 +469,15 @@ namespace FreeSql.Aop internal Stopwatch StopwatchInternal => Stopwatch; public string Operation { get; } public object Value { get; } + /// + /// 状态数据,可与 TraceAfter 共享 + /// + public Dictionary States { get; protected set; } } public class TraceAfterEventArgs : TraceBeforeEventArgs { 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.Exception = exception;