平安校园
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.
 
 
 
 
 
 

80 regels
2.1 KiB

  1. //
  2. namespace SafeCampus.SqlSugar;
  3. /// <summary>
  4. /// SqlSugar 事务和工作单元
  5. /// </summary>
  6. public sealed class SqlSugarUnitOfWork : IUnitOfWork
  7. {
  8. /// <summary>
  9. /// SqlSugar 对象
  10. /// </summary>
  11. private readonly ISqlSugarClient _sqlSugarClient;
  12. private readonly ILogger<SqlSugarUnitOfWork> _logger;
  13. /// <summary>
  14. /// 构造函数
  15. /// </summary>
  16. /// <param name="sqlSugarClient"></param>
  17. /// <param name="logger"></param>
  18. public SqlSugarUnitOfWork(ISqlSugarClient sqlSugarClient, ILogger<SqlSugarUnitOfWork> logger)
  19. {
  20. _sqlSugarClient = sqlSugarClient;
  21. _logger = logger;
  22. }
  23. /// <summary>
  24. /// 开启工作单元处理
  25. /// </summary>
  26. /// <param name="context"></param>
  27. /// <param name="unitOfWork"></param>
  28. /// <exception cref="NotImplementedException"></exception>
  29. public void BeginTransaction(FilterContext context, UnitOfWorkAttribute unitOfWork)
  30. {
  31. _sqlSugarClient.AsTenant().BeginTran();
  32. }
  33. /// <summary>
  34. /// 提交工作单元处理
  35. /// </summary>
  36. /// <param name="resultContext"></param>
  37. /// <param name="unitOfWork"></param>
  38. /// <exception cref="NotImplementedException"></exception>
  39. public void CommitTransaction(FilterContext resultContext, UnitOfWorkAttribute unitOfWork)
  40. {
  41. _sqlSugarClient.AsTenant().CommitTran();
  42. }
  43. /// <summary>
  44. /// 回滚工作单元处理
  45. /// </summary>
  46. /// <param name="resultContext"></param>
  47. /// <param name="unitOfWork"></param>
  48. /// <exception cref="NotImplementedException"></exception>
  49. public void RollbackTransaction(FilterContext resultContext, UnitOfWorkAttribute unitOfWork)
  50. {
  51. _sqlSugarClient.AsTenant().RollbackTran();
  52. }
  53. /// <summary>
  54. /// 执行完毕(无论成功失败)
  55. /// </summary>
  56. /// <param name="context"></param>
  57. /// <param name="resultContext"></param>
  58. /// <exception cref="NotImplementedException"></exception>
  59. public void OnCompleted(FilterContext context, FilterContext resultContext)
  60. {
  61. _sqlSugarClient.Dispose();
  62. }
  63. }