UnitOfWorkRepository.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using AipGateway.API.Domain.Entities;
  2. using AipGateway.API.Domain.IRepositories.IGenericRepositories;
  3. using AipGateway.API.Domain.Models;
  4. using Microsoft.EntityFrameworkCore;
  5. using AipGateway.API.Infrastructure.Persistence;
  6. using Microsoft.Extensions.Logging;
  7. namespace AipGateway.API.Infrastructure.DataAccess
  8. {
  9. public class UnitOfWorkRepository : IUnitOfWork
  10. {
  11. private readonly ILogger<UnitOfWorkRepository> _log;
  12. private readonly ApplicationDbContext _dbContext;
  13. private readonly ConnectionInfo _connectionInfo;
  14. private IGenericRepository<TbLinkedSystem>? _linkedSystemRepository;
  15. private IGenericRepository<TbLinkedServer>? _linkedServerRepository;
  16. private IGenericRepository<TbLinkedApiKey>? _linkedApiKeyRepository;
  17. private IGenericRepository<TbLinkedDecryptKey>? _linkedDescryptRepository;
  18. private IGenericRepository<TbAipLabel>? _aipAipLabelRepository;
  19. private IGenericRepository<TbAipPolicy>? _aipAipPolicyRepository;
  20. private IGenericRepository<TbAipProtection>? _aipAipProtectionRepository;
  21. private IGenericRepository<TbAipApiCallLog>? _aipApiCallLogRepository;
  22. private IGenericRepository<TbAipFileJobLog>? _aipFileJobLogRepository;
  23. public UnitOfWorkRepository(ILogger<UnitOfWorkRepository> logger, ApplicationDbContext appDbContext, ConnectionInfo connectionInfo)
  24. {
  25. _log = logger;
  26. _dbContext = appDbContext;
  27. _connectionInfo = connectionInfo;
  28. _log.LogError("ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo: UnitOfWorkRepository");
  29. }
  30. public IGenericRepository<TbLinkedSystem> LinkedSystemRepository {
  31. get
  32. {
  33. if (_linkedSystemRepository == null)
  34. _linkedSystemRepository = new GenericRepository<TbLinkedSystem>(_dbContext, _connectionInfo);
  35. return _linkedSystemRepository;
  36. }
  37. }
  38. public IGenericRepository<TbLinkedServer> LinkedServerRepository {
  39. get
  40. {
  41. if (_linkedServerRepository == null)
  42. _linkedServerRepository = new GenericRepository<TbLinkedServer>(_dbContext, _connectionInfo);
  43. return _linkedServerRepository;
  44. }
  45. }
  46. public IGenericRepository<TbLinkedApiKey> LinkedApiKeyRepository
  47. {
  48. get
  49. {
  50. if (_linkedApiKeyRepository == null)
  51. _linkedApiKeyRepository = new GenericRepository<TbLinkedApiKey>(_dbContext, _connectionInfo);
  52. return _linkedApiKeyRepository;
  53. }
  54. }
  55. public IGenericRepository<TbLinkedDecryptKey> LinkedDecryptKeyRepository
  56. {
  57. get
  58. {
  59. if (_linkedDescryptRepository == null)
  60. _linkedDescryptRepository = new GenericRepository<TbLinkedDecryptKey>(_dbContext, _connectionInfo);
  61. return _linkedDescryptRepository;
  62. }
  63. }
  64. public IGenericRepository<TbAipLabel> AipLabelRepository
  65. {
  66. get
  67. {
  68. if (_aipAipLabelRepository == null)
  69. _aipAipLabelRepository = new GenericRepository<TbAipLabel>(_dbContext, _connectionInfo);
  70. return _aipAipLabelRepository;
  71. }
  72. }
  73. public IGenericRepository<TbAipPolicy> AipPolicyRepository
  74. {
  75. get
  76. {
  77. if (_aipAipPolicyRepository == null)
  78. _aipAipPolicyRepository = new GenericRepository<TbAipPolicy>(_dbContext, _connectionInfo);
  79. return _aipAipPolicyRepository;
  80. }
  81. }
  82. public IGenericRepository<TbAipProtection> AipProtectionRepository
  83. {
  84. get
  85. {
  86. if (_aipAipProtectionRepository == null)
  87. _aipAipProtectionRepository = new GenericRepository<TbAipProtection>(_dbContext, _connectionInfo);
  88. return _aipAipProtectionRepository;
  89. }
  90. }
  91. public IGenericRepository<TbAipApiCallLog> AipApiCallLogRepository
  92. {
  93. get
  94. {
  95. if (_aipApiCallLogRepository == null)
  96. _aipApiCallLogRepository = new GenericRepository<TbAipApiCallLog>(_dbContext, _connectionInfo);
  97. return _aipApiCallLogRepository;
  98. }
  99. }
  100. public IGenericRepository<TbAipFileJobLog> AipFileJobLogRepository
  101. {
  102. get
  103. {
  104. if (_aipFileJobLogRepository == null)
  105. _aipFileJobLogRepository = new GenericRepository<TbAipFileJobLog>(_dbContext, _connectionInfo);
  106. return _aipFileJobLogRepository;
  107. }
  108. }
  109. public int Complete()
  110. {
  111. return _dbContext.SaveChanges();
  112. }
  113. public void Dispose()
  114. {
  115. Dispose(true);
  116. GC.SuppressFinalize(this);
  117. }
  118. protected virtual void Dispose(bool disposing)
  119. {
  120. if (disposing) _dbContext.Dispose();
  121. }
  122. }
  123. }