123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- using AipGateway.API.Domain.Entities;
- using AipGateway.API.Domain.IRepositories.IGenericRepositories;
- using AipGateway.API.Infrastructure.Persistence;
- using Microsoft.Extensions.Logging;
- using AipGateway.API.Infrastructure.Configurations;
- namespace AipGateway.API.Infrastructure.DataAccess
- {
- public class UnitOfWorkRepository : IUnitOfWork
- {
- private readonly ILogger<UnitOfWorkRepository> _log;
- private readonly ApplicationDbContext _dbContext;
- private readonly ConnectionInfo _connectionInfo;
- private IGenericRepository<TbLinkedSystem>? _linkedSystemRepository;
- private IGenericRepository<TbLinkedServer>? _linkedServerRepository;
- private IGenericRepository<TbLinkedApiKey>? _linkedApiKeyRepository;
- private IGenericRepository<TbLinkedDecryptKey>? _linkedDescryptRepository;
- private IGenericRepository<TbAipLabel>? _aipAipLabelRepository;
- private IGenericRepository<TbAipPolicy>? _aipAipPolicyRepository;
- private IGenericRepository<TbAipProtection>? _aipAipProtectionRepository;
- private IGenericRepository<TbAipApiCallLog>? _aipApiCallLogRepository;
- private IGenericRepository<TbAipFileJobLog>? _aipFileJobLogRepository;
- public UnitOfWorkRepository(ILogger<UnitOfWorkRepository> logger, ApplicationDbContext appDbContext, ConnectionInfo connectionInfo)
- {
- _log = logger;
- _dbContext = appDbContext;
- _connectionInfo = connectionInfo;
- }
- public IGenericRepository<TbLinkedSystem> LinkedSystemRepository {
- get
- {
- if (_linkedSystemRepository == null)
- _linkedSystemRepository = new GenericRepository<TbLinkedSystem>(_dbContext, _connectionInfo);
- return _linkedSystemRepository;
- }
- }
- public IGenericRepository<TbLinkedServer> LinkedServerRepository {
- get
- {
- if (_linkedServerRepository == null)
- _linkedServerRepository = new GenericRepository<TbLinkedServer>(_dbContext, _connectionInfo);
- return _linkedServerRepository;
- }
- }
- public IGenericRepository<TbLinkedApiKey> LinkedApiKeyRepository
- {
- get
- {
- if (_linkedApiKeyRepository == null)
- _linkedApiKeyRepository = new GenericRepository<TbLinkedApiKey>(_dbContext, _connectionInfo);
- return _linkedApiKeyRepository;
- }
- }
- public IGenericRepository<TbLinkedDecryptKey> LinkedDecryptKeyRepository
- {
- get
- {
- if (_linkedDescryptRepository == null)
- _linkedDescryptRepository = new GenericRepository<TbLinkedDecryptKey>(_dbContext, _connectionInfo);
- return _linkedDescryptRepository;
- }
- }
- public IGenericRepository<TbAipLabel> AipLabelRepository
- {
- get
- {
- if (_aipAipLabelRepository == null)
- _aipAipLabelRepository = new GenericRepository<TbAipLabel>(_dbContext, _connectionInfo);
- return _aipAipLabelRepository;
- }
- }
- public IGenericRepository<TbAipPolicy> AipPolicyRepository
- {
- get
- {
- if (_aipAipPolicyRepository == null)
- _aipAipPolicyRepository = new GenericRepository<TbAipPolicy>(_dbContext, _connectionInfo);
- return _aipAipPolicyRepository;
- }
- }
- public IGenericRepository<TbAipProtection> AipProtectionRepository
- {
- get
- {
- if (_aipAipProtectionRepository == null)
- _aipAipProtectionRepository = new GenericRepository<TbAipProtection>(_dbContext, _connectionInfo);
- return _aipAipProtectionRepository;
- }
- }
- public IGenericRepository<TbAipApiCallLog> AipApiCallLogRepository
- {
- get
- {
- if (_aipApiCallLogRepository == null)
- _aipApiCallLogRepository = new GenericRepository<TbAipApiCallLog>(_dbContext, _connectionInfo);
- return _aipApiCallLogRepository;
- }
- }
- public IGenericRepository<TbAipFileJobLog> AipFileJobLogRepository
- {
- get
- {
- if (_aipFileJobLogRepository == null)
- _aipFileJobLogRepository = new GenericRepository<TbAipFileJobLog>(_dbContext, _connectionInfo);
- return _aipFileJobLogRepository;
- }
- }
- public int Complete()
- {
- return _dbContext.SaveChanges();
- }
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- protected virtual void Dispose(bool disposing)
- {
- if (disposing) _dbContext.Dispose();
- }
- }
- }
|