using ExpenseTracker.Application.Common.Interfaces; using ExpenseTracker.Application.Common.Interfaces.Repositories; namespace ExpenseTracker.Persistence.MongoDb; public class MongoDbUnitOfWork : IUnitOfWork { private MongoDbContext _dbContext; public MongoDbUnitOfWork( MongoDbContext dbContext, IAccountRepository accountRepository, ITransactionRepository transactionRepository) { _dbContext = dbContext; AccountRepository = accountRepository; TransactionRepository = transactionRepository; } public IAccountRepository AccountRepository { get; init; } public ITransactionRepository TransactionRepository { get; init; } public int Save() { return _dbContext.SaveAsync(CancellationToken.None).Result; } public async Task SaveAsync(CancellationToken cancellationToken) { return await _dbContext.SaveAsync(cancellationToken); } public void Dispose() { Dispose(disposing: true); GC.SuppressFinalize(this); } public void Dispose(bool disposing) { if (disposing) { _dbContext.Dispose(); } } }