namespace Admin.NET.Core;
///
/// SqlSugar 事务和工作单元
///
public sealed class SqlSugarUnitOfWork : IUnitOfWork
{
///
/// SqlSugar 对象
///
private readonly ISqlSugarClient _sqlSugarClient;
///
/// 构造函数
///
///
public SqlSugarUnitOfWork(ISqlSugarClient sqlSugarClient)
{
_sqlSugarClient = sqlSugarClient;
}
///
/// 开启工作单元处理
///
///
///
///
public void BeginTransaction(FilterContext context, UnitOfWorkAttribute unitOfWork)
{
_sqlSugarClient.AsTenant().BeginTran();
}
///
/// 提交工作单元处理
///
///
///
///
public void CommitTransaction(FilterContext resultContext, UnitOfWorkAttribute unitOfWork)
{
_sqlSugarClient.AsTenant().CommitTran();
}
///
/// 回滚工作单元处理
///
///
///
///
public void RollbackTransaction(FilterContext resultContext, UnitOfWorkAttribute unitOfWork)
{
_sqlSugarClient.AsTenant().RollbackTran();
}
///
/// 执行完毕(无论成功失败)
///
///
///
///
public void OnCompleted(FilterContext context, FilterContext resultContext)
{
_sqlSugarClient.Dispose();
}
}