// namespace SafeCampus.SqlSugar; /// /// SqlSugar 事务和工作单元 /// public sealed class SqlSugarUnitOfWork : IUnitOfWork { /// /// SqlSugar 对象 /// private readonly ISqlSugarClient _sqlSugarClient; private readonly ILogger _logger; /// /// 构造函数 /// /// /// public SqlSugarUnitOfWork(ISqlSugarClient sqlSugarClient, ILogger logger) { _sqlSugarClient = sqlSugarClient; _logger = logger; } /// /// 开启工作单元处理 /// /// /// /// 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(); } }