57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
using cuqmbr.TravelGuide.Application.Common.Interfaces.Persistence;
|
|
using cuqmbr.TravelGuide.Application.Common.Interfaces.Persistence.Repositories;
|
|
using cuqmbr.TravelGuide.Persistence.PostgreSql.Repositories;
|
|
|
|
namespace cuqmbr.TravelGuide.Persistence.PostgreSql;
|
|
|
|
public sealed class PostgreSqlUnitOfWork : UnitOfWork
|
|
{
|
|
private readonly PostgreSqlDbContext _dbContext;
|
|
|
|
public PostgreSqlUnitOfWork(
|
|
PostgreSqlDbContext dbContext)
|
|
{
|
|
_dbContext = dbContext;
|
|
|
|
CountryRepository = new PostgreSqlCountryRepository(_dbContext);
|
|
RegionRepository = new PostgreSqlRegionRepository(_dbContext);
|
|
CityRepository = new PostgreSqlCityRepository(_dbContext);
|
|
AddressRepository = new PostgreSqlAddressRepository(_dbContext);
|
|
RouteRepository = new PostgreSqlRouteRepository(_dbContext);
|
|
}
|
|
|
|
public CountryRepository CountryRepository { get; init; }
|
|
|
|
public RegionRepository RegionRepository { get; init; }
|
|
|
|
public CityRepository CityRepository { get; init; }
|
|
|
|
public AddressRepository AddressRepository { get; init; }
|
|
|
|
public RouteRepository RouteRepository { get; init; }
|
|
|
|
public int Save()
|
|
{
|
|
return _dbContext.SaveChanges();
|
|
}
|
|
|
|
public async Task<int> SaveAsync(CancellationToken cancellationToken)
|
|
{
|
|
return await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Dispose(disposing: true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
public void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
_dbContext.Dispose();
|
|
}
|
|
}
|
|
}
|