- 增加 Aop Before/After States 共享状态;

This commit is contained in:
2881099 2021-02-19 17:47:06 +08:00
parent 423fabd7c8
commit ef6665ee29
4 changed files with 88 additions and 21 deletions

View File

@ -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();

View File

@ -512,14 +512,5 @@
<param name="that"></param>
<returns></returns>
</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>
</doc>

View File

@ -3458,6 +3458,11 @@
参数化命令
</summary>
</member>
<member name="P:FreeSql.Aop.CurdBeforeEventArgs.States">
<summary>
状态数据,可与 CurdAfter 共享
</summary>
</member>
<member name="P:FreeSql.Aop.CurdAfterEventArgs.Exception">
<summary>
发生的错误
@ -3488,6 +3493,11 @@
实体类型
</summary>
</member>
<member name="P:FreeSql.Aop.SyncStructureBeforeEventArgs.States">
<summary>
状态数据,可与 SyncStructureAfter 共享
</summary>
</member>
<member name="P:FreeSql.Aop.SyncStructureAfterEventArgs.Sql">
<summary>
执行的 SQL
@ -3548,6 +3558,11 @@
标识符,可将 CommandBefore 与 CommandAfter 进行匹配
</summary>
</member>
<member name="P:FreeSql.Aop.CommandBeforeEventArgs.States">
<summary>
状态数据,可与 CommandAfter 共享
</summary>
</member>
<member name="P:FreeSql.Aop.CommandAfterEventArgs.Exception">
<summary>
发生的错误
@ -3573,6 +3588,11 @@
标识符,可将 TraceBeforeEventArgs 与 TraceAfterEventArgs 进行匹配
</summary>
</member>
<member name="P:FreeSql.Aop.TraceBeforeEventArgs.States">
<summary>
状态数据,可与 TraceAfter 共享
</summary>
</member>
<member name="P:FreeSql.Aop.TraceAfterEventArgs.Remark">
<summary>
备注

View File

@ -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<string, object>())
{
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.Stopwatch = stopwatch;
@ -178,6 +178,7 @@ namespace FreeSql.Aop
this.CurdType = curdType;
this.Sql = sql;
this.DbParms = dbParms;
this.States = states;
}
/// <summary>
@ -206,12 +207,16 @@ namespace FreeSql.Aop
/// 参数化命令
/// </summary>
public DbParameter[] DbParms { get; }
/// <summary>
/// 状态数据,可与 CurdAfter 共享
/// </summary>
public Dictionary<string, object> 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<string, object>())
{
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.Stopwatch = stopwatch;
this.EntityTypes = entityTypes;
this.States = states;
}
/// <summary>
@ -262,11 +268,15 @@ namespace FreeSql.Aop
/// 实体类型
/// </summary>
public Type[] EntityTypes { get; }
/// <summary>
/// 状态数据,可与 SyncStructureAfter 共享
/// </summary>
public Dictionary<string, object> 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<string, object>())
{
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.Stopwatch = stopwatch;
this.Command = command;
this.States = states;
}
/// <summary>
@ -399,11 +410,15 @@ namespace FreeSql.Aop
protected Stopwatch Stopwatch { get; }
internal Stopwatch StopwatchInternal => Stopwatch;
public DbCommand Command { get; }
/// <summary>
/// 状态数据,可与 CommandAfter 共享
/// </summary>
public Dictionary<string, object> 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<string, object>())
{
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.Stopwatch = stopwatch;
this.Operation = operation;
this.Value = value;
this.States = states;
}
/// <summary>
@ -453,11 +469,15 @@ namespace FreeSql.Aop
internal Stopwatch StopwatchInternal => Stopwatch;
public string Operation { get; }
public object Value { get; }
/// <summary>
/// 状态数据,可与 TraceAfter 共享
/// </summary>
public Dictionary<string, object> 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;