You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.1 KiB
69 lines
2.1 KiB
6 months ago
|
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
|
||
|
//
|
||
|
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
|
||
|
|
||
|
namespace Admin.NET.Core;
|
||
|
|
||
|
/// <summary>
|
||
|
/// SqlSugar 事务和工作单元
|
||
|
/// </summary>
|
||
|
public sealed class SqlSugarUnitOfWork : IUnitOfWork
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// SqlSugar 对象
|
||
|
/// </summary>
|
||
|
private readonly ISqlSugarClient _sqlSugarClient;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 构造函数
|
||
|
/// </summary>
|
||
|
/// <param name="sqlSugarClient"></param>
|
||
|
public SqlSugarUnitOfWork(ISqlSugarClient sqlSugarClient)
|
||
|
{
|
||
|
_sqlSugarClient = sqlSugarClient;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 开启工作单元处理
|
||
|
/// </summary>
|
||
|
/// <param name="context"></param>
|
||
|
/// <param name="unitOfWork"></param>
|
||
|
/// <exception cref="NotImplementedException"></exception>
|
||
|
public void BeginTransaction(FilterContext context, UnitOfWorkAttribute unitOfWork)
|
||
|
{
|
||
|
_sqlSugarClient.AsTenant().BeginTran();
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 提交工作单元处理
|
||
|
/// </summary>
|
||
|
/// <param name="resultContext"></param>
|
||
|
/// <param name="unitOfWork"></param>
|
||
|
/// <exception cref="NotImplementedException"></exception>
|
||
|
public void CommitTransaction(FilterContext resultContext, UnitOfWorkAttribute unitOfWork)
|
||
|
{
|
||
|
_sqlSugarClient.AsTenant().CommitTran();
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 回滚工作单元处理
|
||
|
/// </summary>
|
||
|
/// <param name="resultContext"></param>
|
||
|
/// <param name="unitOfWork"></param>
|
||
|
/// <exception cref="NotImplementedException"></exception>
|
||
|
public void RollbackTransaction(FilterContext resultContext, UnitOfWorkAttribute unitOfWork)
|
||
|
{
|
||
|
_sqlSugarClient.AsTenant().RollbackTran();
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 执行完毕(无论成功失败)
|
||
|
/// </summary>
|
||
|
/// <param name="context"></param>
|
||
|
/// <param name="resultContext"></param>
|
||
|
/// <exception cref="NotImplementedException"></exception>
|
||
|
public void OnCompleted(FilterContext context, FilterContext resultContext)
|
||
|
{
|
||
|
_sqlSugarClient.Dispose();
|
||
|
}
|
||
|
}
|