Blame view

Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Uow/SqlSugarTransactionApi.cs 1.27 KB
515fceeb   “wangming”   框架初始化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  using Volo.Abp.Uow;
  using Yi.Framework.SqlSugarCore.Abstractions;
  
  namespace Yi.Framework.SqlSugarCore.Uow
  {
      /// <summary>
      /// SqlSugar事务API实现
      /// </summary>
      public class SqlSugarTransactionApi : ITransactionApi, ISupportsRollback
      {
          private readonly ISqlSugarDbContext _dbContext;
  
          public SqlSugarTransactionApi(ISqlSugarDbContext dbContext)
          {
              _dbContext = dbContext;
          }
  
          /// <summary>
          /// 获取数据库上下文
          /// </summary>
          public ISqlSugarDbContext GetDbContext()
          {
              return _dbContext;
          }
  
          /// <summary>
          /// 提交事务
          /// </summary>
          public async Task CommitAsync(CancellationToken cancellationToken = default)
          {
              await _dbContext.SqlSugarClient.Ado.CommitTranAsync();
          }
  
          /// <summary>
          /// 回滚事务
          /// </summary>
          public async Task RollbackAsync(CancellationToken cancellationToken = default)
          {
              await _dbContext.SqlSugarClient.Ado.RollbackTranAsync();
          }
  
          /// <summary>
          /// 释放资源
          /// </summary>
          public void Dispose()
          {
              _dbContext.SqlSugarClient.Ado.Dispose();
          }
      }
  }