TestService.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using Admin.NET.Application.Const;
  2. using Furion.DatabaseAccessor;
  3. using Furion.Logging;
  4. using Microsoft.AspNetCore.Authorization;
  5. namespace Admin.NET.Application.Serice;
  6. /// <summary>
  7. /// 自己业务服务
  8. /// </summary>
  9. [ApiDescriptionSettings(TestConst.GroupName, Name = "XXX模块", Order = 200)]
  10. [AllowAnonymous]
  11. [LoggingMonitor]
  12. public class TestService : IDynamicApiController, ITransient
  13. {
  14. private readonly SqlSugarRepository<Test> _testRep;
  15. public TestService(SqlSugarRepository<Test> testRep)
  16. {
  17. _testRep = testRep;
  18. }
  19. /// <summary>
  20. /// 获取列表
  21. /// </summary>
  22. /// <returns></returns>
  23. [HttpGet("/test/list")]
  24. public async Task<List<Test>> GetTestList()
  25. {
  26. return await _testRep.GetListAsync();
  27. }
  28. /// <summary>
  29. /// 事务和工作单元测试
  30. /// </summary>
  31. /// <returns></returns>
  32. [HttpGet("/test/list2")]
  33. [UnitOfWork]
  34. public async Task<List<Test>> TestUnitOfWork()
  35. {
  36. await _testRep.InsertAsync(new Test() { Name = "admin" });
  37. throw new Exception("异常");
  38. return await _testRep.GetListAsync();
  39. }
  40. }