TestService.cs 1.1 KB

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